我有一个带有以下str的数据框:
> str(sum_aut_comb)
'data.frame': 1296 obs. of 8 variables:
$ Season : Factor w/ 2 levels "Summer","Autumn": 1 1 1 1 1 1 1 1 1 1 ...
$ Site : Factor w/ 27 levels "Afon Cadnant",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Isotope: Factor w/ 4 levels "14CAA","14CGlu",..: 1 1 1 1 1 1 2 2 2 2 ...
$ Time : Factor w/ 6 levels "0","2","24","48",..: 1 2 3 4 5 6 1 2 3 4 ...
$ n : int 3 3 3 3 3 3 3 3 3 3 ...
$ mean : num 100 68.3 36.8 28 70 ...
$ sd : num 0 4.375 2.422 0.829 7.885 ...
$ se : num 0 2.526 1.398 0.479 4.553 ...
根据这些数据,我需要使用以下表格创建多个图表。 对于每个站点,我需要4个图表(在一个图上),代表同位素因子的4个级别。 x =时间,Y =平均值(带有误差条)。 在每个图表上,我需要2个数据系列,代表季节因子的2个级别。 我显然可以通过子集化创建新的数据帧来实现这一点,但是使用R的重点是什么? 我不确定“自动化”此程序的最佳方法。
以下是由27个网站之一组成的数据框ggtest
:
Season Site Isotope Time n mean sd se
1 Summer Afon Cadnant 14CAA 0 3 100.00000 0.0000000 0.0000000
2 Summer Afon Cadnant 14CAA 2 3 68.26976 4.3753314 2.5260988
3 Summer Afon Cadnant 14CAA 5 3 69.95398 7.8854431 4.5526627
4 Summer Afon Cadnant 14CAA 24 3 36.84054 2.4218456 1.3982532
5 Summer Afon Cadnant 14CAA 48 3 27.96619 0.8291340 0.4787008
6 Summer Afon Cadnant 14CAA 72 3 26.28713 1.4548194 0.8399404
7 Summer Afon Cadnant 14CGlu 0 3 100.00000 0.0000000 0.0000000
8 Summer Afon Cadnant 14CGlu 2 3 81.06818 3.2834934 1.8957258
9 Summer Afon Cadnant 14CGlu 5 3 85.16767 4.3191444 2.4936592
10 Summer Afon Cadnant 14CGlu 24 3 30.71960 1.3568712 0.7833899
11 Summer Afon Cadnant 14CGlu 48 3 10.25603 0.7581894 0.4377409
12 Summer Afon Cadnant 14CGlu 72 3 15.06344 1.4195073 0.8195529
13 Summer Afon Cadnant 14cGlu6P 0 3 100.00000 0.0000000 0.0000000
14 Summer Afon Cadnant 14cGlu6P 2 3 98.03503 0.2479080 0.1431298
15 Summer Afon Cadnant 14cGlu6P 5 3 98.65640 0.2283632 0.1318455
16 Summer Afon Cadnant 14cGlu6P 24 3 75.99561 3.0865652 1.7820292
17 Summer Afon Cadnant 14cGlu6P 48 3 28.06327 1.1166302 0.6446867
18 Summer Afon Cadnant 14cGlu6P 72 3 11.64653 0.9471871 0.5468587
19 Summer Afon Cadnant 33P 0 3 100.00000 0.0000000 0.0000000
20 Summer Afon Cadnant 33P 2 3 90.47689 1.9835440 1.1451997
21 Summer Afon Cadnant 33P 5 3 84.11501 1.0971534 0.6334418
22 Summer Afon Cadnant 33P 24 3 52.68886 1.6789763 0.9693574
23 Summer Afon Cadnant 33P 48 3 29.02815 1.7557808 1.0137005
24 Summer Afon Cadnant 33P 72 3 24.74297 1.3983865 0.8073588
25 Autumn Afon Cadnant 14CAA 0 3 100.00000 0.0000000 0.0000000
26 Autumn Afon Cadnant 14CAA 2 3 68.26976 4.3753314 2.5260988
27 Autumn Afon Cadnant 14CAA 5 3 69.95398 7.8854431 4.5526627
28 Autumn Afon Cadnant 14CAA 24 3 36.84054 2.4218456 1.3982532
29 Autumn Afon Cadnant 14CAA 48 3 27.96619 0.8291340 0.4787008
30 Autumn Afon Cadnant 14CAA 72 3 26.28713 1.4548194 0.8399404
31 Autumn Afon Cadnant 14CGlu 0 3 100.00000 0.0000000 0.0000000
32 Autumn Afon Cadnant 14CGlu 2 3 81.06818 3.2834934 1.8957258
33 Autumn Afon Cadnant 14CGlu 5 3 85.16767 4.3191444 2.4936592
34 Autumn Afon Cadnant 14CGlu 24 3 30.71960 1.3568712 0.7833899
35 Autumn Afon Cadnant 14CGlu 48 3 10.25603 0.7581894 0.4377409
36 Autumn Afon Cadnant 14CGlu 72 3 15.06344 1.4195073 0.8195529
37 Autumn Afon Cadnant 14cGlu6P 0 3 100.00000 0.0000000 0.0000000
38 Autumn Afon Cadnant 14cGlu6P 2 3 98.03503 0.2479080 0.1431298
39 Autumn Afon Cadnant 14cGlu6P 5 3 98.65640 0.2283632 0.1318455
40 Autumn Afon Cadnant 14cGlu6P 24 3 75.99561 3.0865652 1.7820292
41 Autumn Afon Cadnant 14cGlu6P 48 3 28.06327 1.1166302 0.6446867
42 Autumn Afon Cadnant 14cGlu6P 72 3 11.64653 0.9471871 0.5468587
43 Autumn Afon Cadnant 33P 0 3 100.00000 0.0000000 0.0000000
44 Autumn Afon Cadnant 33P 2 3 90.47689 1.9835440 1.1451997
45 Autumn Afon Cadnant 33P 5 3 84.11501 1.0971534 0.6334418
46 Autumn Afon Cadnant 33P 24 3 52.68886 1.6789763 0.9693574
47 Autumn Afon Cadnant 33P 48 3 29.02815 1.7557808 1.0137005
48 Autumn Afon Cadnant 33P 72 3 24.74297 1.3983865 0.8073588
我设法编写了以下ggplot代码:
ggplot(data = ggtest, aes(x= Time, y = mean, colour = Season))+geom_point() + facet_wrap(~Isotope, ncol=2)
我没有设法让代码按照我想要的方式工作,因为我希望每个剧情都有2个系列 - 一个夏天和一个秋天。
此外,主数据框sum_aut_comb
包含27个网站,那么将上述ggplot代码应用于因子Site
的每个级别的最佳方法是什么?