I have some data recorded over a period of months from 5 treatments (incl. control). I'm using ggplot to plot the data as a time series and have generated a data frame of the means of the raw data and standard error for each date.
I'm trying to plot all five treatments on the same graph and show the error bars with it. I'm able to a). plot one treatment group and show the error bars and b). plot all five treatments but not show the error bars.
Here's my data (I've only included two treatments to keep things tidy here)
dates c_mean_am c_se_am T1_mean_am T1_se_am
1 2017-01-31 284.135 27.43111 228.935 23.39037
2 2017-02-09 226.944 13.08237 173.241 13.42946
3 2017-02-23 281.135 15.89709 252.665 20.73417
4 2017-03-14 265.655 15.29930 238.225 17.47501
5 2017-04-06 312.785 13.08237 237.485 13.42946
- c_mean_am = control means
- c_se_am = standard error for controls
- T1_mean_am = Treatment 1 means
- T1_se_am = standard error for Treatment 1
Here's my code to achieve option a) above
ggplot(summary, aes(x=dates, y=c_mean_am),xlab="Date") +
geom_point(shape = 19, size = 2,color="blue") +
geom_line(color="blue") +
geom_errorbar(aes(x=dates, ymin=c_mean_am-c_se_am, ymax=c_mean_am+c_se_am), color="blue", width=0.25)
Here's the code for option b) above
sp <- ggplot(summary,aes(dates,y = Cond,color=Treatment)) +
geom_line(aes(y = c_mean_am, color = "Control")) +
geom_line(aes(y = T1_mean_am, color = "T1")) +
geom_point(aes(y = c_mean_am, color = "Control")) +
geom_point(aes(y = T1_mean_am, color = "T1"))
sp2<- sp +
scale_color_manual(breaks = c("Control", "T1","T2"), values=c("blue", "yellow"))
sp2
How can I get the error bars on the second plot using the same colours as the points and lines?
Thanks
AB