我正在尝试使用错误区域(而不是错误条)创建折线图。这是我的数据:
data <- read.table(text = "
Water_mass Time Abundance Mean sd Upper Lower
1 FRONT 1 265 281.75000 54.524459 336.27446 227.22554
2 FRONT 1 359 281.75000 54.524459 336.27446 227.22554
3 FRONT 1 272 281.75000 54.524459 336.27446 227.22554
4 FRONT 1 231 281.75000 54.524459 336.27446 227.22554
5 FRONT 188 40 57.80000 19.227584 77.02758 38.57242
6 FRONT 188 57 57.80000 19.227584 77.02758 38.57242
7 FRONT 188 38 57.80000 19.227584 77.02758 38.57242
8 FRONT 188 73 57.80000 19.227584 77.02758 38.57242
9 FRONT 188 81 57.80000 19.227584 77.02758 38.57242
10 FRONT 353 131 346.25000 253.898109 600.14811 92.35189
11 FRONT 353 622 346.25000 253.898109 600.14811 92.35189
12 FRONT 353 502 346.25000 253.898109 600.14811 92.35189
13 FRONT 353 130 346.25000 253.898109 600.14811 92.35189
14 FRONT 434 38 47.50000 13.435029 60.93503 34.06497
15 FRONT 434 57 47.50000 13.435029 60.93503 34.06497
16 FRONT 476 52 49.50000 3.535534 53.03553 45.96447
17 FRONT 476 47 49.50000 3.535534 53.03553 45.96447
18 NW 1 232 232.00000 NA NA NA
19 NW 154 140 138.50000 2.121320 140.62132 136.37868
20 NW 154 137 138.50000 2.121320 140.62132 136.37868
21 NW 188 252 253.00000 1.414214 254.41421 251.58579
22 NW 188 254 253.00000 1.414214 254.41421 251.58579
23 NW 353 3846 1957.50000 2670.742313 4628.24231 -713.24231
24 NW 353 69 1957.50000 2670.742313 4628.24231 -713.24231
25 NW 434 162 181.75000 80.748065 262.49806 101.00194
26 NW 434 93 181.75000 80.748065 262.49806 101.00194
27 NW 434 184 181.75000 80.748065 262.49806 101.00194
28 NW 434 288 181.75000 80.748065 262.49806 101.00194
29 NW 476 149 181.00000 45.254834 226.25483 135.74517
30 NW 476 213 181.00000 45.254834 226.25483 135.74517
31 SAW 1 143 147.16667 13.717386 160.88405 133.44928
32 SAW 1 137 147.16667 13.717386 160.88405 133.44928
33 SAW 1 170 147.16667 13.717386 160.88405 133.44928
34 SAW 1 149 147.16667 13.717386 160.88405 133.44928
35 SAW 1 153 147.16667 13.717386 160.88405 133.44928
36 SAW 1 131 147.16667 13.717386 160.88405 133.44928
37 SAW 154 79 61.66667 11.269428 72.93609 50.39724
38 SAW 154 65 61.66667 11.269428 72.93609 50.39724
39 SAW 154 52 61.66667 11.269428 72.93609 50.39724
40 SAW 154 48 61.66667 11.269428 72.93609 50.39724
41 SAW 154 74 61.66667 11.269428 72.93609 50.39724
42 SAW 154 52 61.66667 11.269428 72.93609 50.39724
43 SAW 154 51 61.66667 11.269428 72.93609 50.39724
44 SAW 154 69 61.66667 11.269428 72.93609 50.39724
45 SAW 154 65 61.66667 11.269428 72.93609 50.39724
46 SAW 188 68 55.50000 9.327379 64.82738 46.17262
47 SAW 188 47 55.50000 9.327379 64.82738 46.17262
48 SAW 188 57 55.50000 9.327379 64.82738 46.17262
49 SAW 188 50 55.50000 9.327379 64.82738 46.17262
50 SAW 353 868 696.60000 229.660184 926.26018 466.93982
51 SAW 353 728 696.60000 229.660184 926.26018 466.93982
52 SAW 353 354 696.60000 229.660184 926.26018 466.93982
53 SAW 353 930 696.60000 229.660184 926.26018 466.93982
54 SAW 353 603 696.60000 229.660184 926.26018 466.93982
55 SAW 434 31 31.57143 6.106203 37.67763 25.46523
56 SAW 434 33 31.57143 6.106203 37.67763 25.46523
57 SAW 434 19 31.57143 6.106203 37.67763 25.46523
58 SAW 434 30 31.57143 6.106203 37.67763 25.46523
59 SAW 434 35 31.57143 6.106203 37.67763 25.46523
60 SAW 434 36 31.57143 6.106203 37.67763 25.46523
61 SAW 434 37 31.57143 6.106203 37.67763 25.46523
62 SAW 476 96 60.75000 24.185050 84.93505 36.56495
63 SAW 476 54 60.75000 24.185050 84.93505 36.56495
64 SAW 476 41 60.75000 24.185050 84.93505 36.56495
65 SAW 476 52 60.75000 24.185050 84.93505 36.56495
66 STW 1 194 177.66667 20.256686 197.92335 157.40998
67 STW 1 184 177.66667 20.256686 197.92335 157.40998
68 STW 1 155 177.66667 20.256686 197.92335 157.40998
69 STW 154 44 49.66667 6.658328 56.32499 43.00834
70 STW 154 57 49.66667 6.658328 56.32499 43.00834
71 STW 154 48 49.66667 6.658328 56.32499 43.00834
72 STW 188 185 101.33333 72.500575 173.83391 28.83276
73 STW 188 57 101.33333 72.500575 173.83391 28.83276
74 STW 188 62 101.33333 72.500575 173.83391 28.83276
75 STW 353 2846 3367.66667 890.594371 4258.26104 2477.07230
76 STW 353 2861 3367.66667 890.594371 4258.26104 2477.07230
77 STW 353 4396 3367.66667 890.594371 4258.26104 2477.07230
78 STW 434 73 54.50000 26.162951 80.66295 28.33705
79 STW 434 36 54.50000 26.162951 80.66295 28.33705
80 STW 476 100 135.20000 31.523007 166.72301 103.67699
81 STW 476 115 135.20000 31.523007 166.72301 103.67699
82 STW 476 180 135.20000 31.523007 166.72301 103.67699
83 STW 476 129 135.20000 31.523007 166.72301 103.67699
84 STW 476 152 135.20000 31.523007 166.72301 103.67699
", header = TRUE)
使用此代码,我可以创建一个类似于我想要的图表:
ggplot(data,aes(x=Time,y=Abundance,col=Water_mass))+ geom_point() + ylab("Abundance")+ xlab("Time (days)") +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.border = element_rect(colour = "lightgray", fill=NA),
panel.background = element_blank())+
theme(strip.background = element_blank()) +
labs(colour="Water mass") +
geom_point(size=3) +
scale_y_continuous(limit=c(0,NA),oob=squish) +
geom_ribbon(aes(ymin = b$Lower, ymax = b$Upper, fill = b$Water_mass), data= b, alpha = 0.2, show.legend = FALSE, colour=NA)+
geom_line(aes(y=Mean, colour=Water_mass), data= b, size=1.5)
但是,如果线条平滑,我更喜欢它。我能够平滑均值,但不是信心区域:
ggplot(data,aes(x=Time,y=Abundance,col=Water_mass))+ geom_point() +
ylab("Abundance")+ xlab("Time (days)") +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.border = element_rect(colour = "lightgray", fill=NA),
panel.background = element_blank())+
theme(strip.background = element_blank()) +
labs(colour="Water mass") +
geom_point(size=3) +
scale_y_continuous(limit=c(0,NA),oob=squish) +
geom_ribbon(aes(ymin = b$Lower, ymax = b$Upper, fill = b$Water_mass), data= b, alpha = 0.2, show.legend = FALSE, colour=NA)+
stat_smooth(se=F, size=1.5)
是否也可以平滑置信区域?
我也试过这个,它看起来像我想要的方式,除了它显示平均值的95%置信区间,而不是数据的一些传播度量:
ggplot(data,aes(x=Time,y=Abundance,col=Water_mass))+ geom_point() + ylab("Abundance")+ xlab("Time (days)") +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.border = element_rect(colour = "lightgray", fill=NA),
panel.background = element_blank())+
theme(strip.background = element_blank()) +
labs(colour="Water mass") + geom_point(size=3) +
geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95, aes(fill = Water_mass), show.legend = FALSE) +
scale_y_continuous(limit=c(0,NA),oob=squish)