I have a data frame with the following 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 ...
From these data I need to create multiple plots with the following form. For each site I require 4 graphs (on one plot) representing the 4 levels of the Isotope factor. x = Time, Y = mean (with se error bars). On each graph I need 2 data series representing the 2 levels of the Season factor. I can obviously do this by creating new data frames by subsetting but then what is the point of using R? I'm not sure of the best way to "automate" this procedure.
Here is a dataframe ggtest
consisting of one of the 27 sites:
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
I have managed to write the following ggplot code:
ggplot(data = ggtest, aes(x= Time, y = mean, colour = Season))+geom_point() + facet_wrap(~Isotope, ncol=2)
I haven't managed to get the code working as I would like as I want 2 series for each plot- one of summer and one of Autumn.
Also, the main dataframe sum_aut_comb
contains 27 sites so what is the best way to apply the above ggplot code to each level of the factor Site
?