Reputation: 1196
I have multiple sites that I sample multiple times (different dates) with which I run time-series experiments to obtain a value for each time point in that series (for each site there are 4 time points). I would like to graph each time series (Time..hours.
) (x-axis) versus their values (Sample.N2O.gas...ppm.
)(y-axis) for each site for its respective date and have multiple plots to view all this data at once.
I'm new to R, so I'm not sure if attaching the image of my data is helpful or not. Data
What I've found so far is:
plots <- data %>% group_by(Site, Date, Treatment, Rep) %>% do(plots=ggplot(data=.)) +
aes(x=Time..hours., y=Sample.N2O.gas...ppm.) + geom_point()
but when I run plots, I just get an output table '#A Tibble 149x5".
Here's what I've copied from my dput output:
data = structure(list(Site = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("QA1", "QA1 ",
"QA2", "W1", "W2", "W3", "W4"), class = "factor"), Date = structure(c(1462860000,
1462860000, 1462860000, 1462860000, 1462860000, 1462860000, 1462860000,
1462860000, 1462860000, 1462860000, 1462860000, 1462860000, 1462860000,
1462860000, 1462860000, 1462860000, 1462860000, 1462860000, 1462860000,
1462860000, 1462860000, 1462860000, 1462860000, 1462860000, 1462860000,
1462860000, 1462860000, 1462860000, 1462860000, 1462860000, 1462860000,
1462860000), class = c("POSIXct", "POSIXt"), tzone = ""), Treatment = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Control",
"DEA", "Denit"), class = "factor"), Rep = c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), Time..hours. = c(0.333333333,
1.166666667, 2, 2.833333333, 0.333333333, 1.166666667, 2, 2.833333333,
0.333333333, 1.166666667, 2, 2.833333333, 0.333333333, 1.166666667,
2, 2.833333333, 0.333333333, 1.166666667, 2, 2.833333333, 0.333333333,
1.166666667, 2, 2.833333333, 0.333333333, 1.166666667, 2, 2.833333333,
0.333333333, 1.166666667, 2, 2.833333333), Sample.N2O.gas...ppm. = c(0.02536993437111,
0.02539270198174, 0.0258252865837, 0.02236460976796, 0.01136785383374,
0.00886341666446, 0.01291605135657, 0.01583030551719, 0.05517273668559,
0.15960776664476, 0.12206397671612, 0.10999714308229, 0.08618222236346,
0.062344534034, 0.0527366023482, 0.05845127261629, 0.03570642959706,
0.05093796110844, 0.04784156606278, 0.05763163863362, 24.1815481999959,
43.9535598867979, 76.0087551511654, 97.5847143861169, 26.1044322512172,
42.2811119155545, 82.8088875655402, 109.127381921808, 24.9257144556248,
46.2630281688243, 84.5042194191463, 102.597585589484)), .Names = c("Site",
"Date", "Treatment", "Rep", "Time..hours.", "Sample.N2O.gas...ppm."
), row.names = c(NA, 32L), class = "data.frame")
Upvotes: 1
Views: 736
Reputation: 5068
That's because you've created a list of plots (technically a tibble of plots). To view the first plot in the list, say, you'll need to do plots[[1]]
Addendum: Actually, your code in its current form doesn't quite work. Did you mean to do the following?
plots <- data %>% group_by(Site, Date, Treatment, Rep) %>% do(plots=ggplot(data=.) +
aes(x=Time..hours., y=Sample.N2O.gas...ppm.) + geom_point())
If so, then (strangely), the plots are buried in a list called plots. You can access the first one with plots$plots[[1]]
, and show all of them by just going plots$plots
.
Upvotes: 1