开发者

Time series plot with groups using ggplot2

I have an experiment where three evolving populations of yeast have been studied over time. At discrete time points, we measured their growth, which is the response variable. I basically want to plot the growth of yeast as a time series, using boxplots to summarise the measurements taken at each point, and 开发者_StackOverflowplotting each of the three populations separately. Basically, something that looks like this (as a newbie, I don't get to post actual images, so x,y,z refer to the three replicates):

|              xyz
|       x z    xyz
|  y    xyz
| xyz    y
| x z     
|
-----------------------
  t0     t1    t2

How can this be done using ggplot2? I have a feeling that there must be a simple and elegant solution, but I can't find it.


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)

Time series plot with groups using ggplot2

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜