Time series chart with groups using ggplot2

I have an experiment in which three evolving yeast populations have been studied over time. At discrete time points, we measured their growth, which is a response variable. I mainly want to talk about the growth of yeast as a time series, using boxes to summarize the measurements taken at each point and compile each of the three populations separately. Basically, something similar to this (as a newbie, I can't post actual images, so x, y, z refer to three replicas):

| xyz | xz xyz | y xyz | xyz y | xz | ----------------------- t0 t1 t2 

How can this be done with ggplot2? I have a feeling that there should be a simple and elegant solution, but I can not find it.

+4
source share
1 answer

Try this code:

 require(ggplot2) df <- data.frame( time = rep(seq(Sys.Date(), len = 3, by = "1 day"), 10), y = rep(1:3, 10, each = 3) + rnorm(30), group = rep(c("x", "y", "z"), 10, each = 3) ) df$time <- factor(format(df$time, format = "%Y-%m-%d")) p <- ggplot(df, aes(x = time, y = y, fill = group)) + geom_boxplot() print(p) 

Fig1

Only with x = factor(time) , ggplot(df, aes(x = factor(time), y = y, fill = group)) + geom_boxplot() + scale_x_date() did not work.

Pre-processing, factor(format(df$time, format = "%Y-%m-%d")) , was necessary for this form of graphics.

+5
source

All Articles