My data looks like this:
> head(Full.df)
Date Month Week Year Count.S Count.G Count.W Count.F
1 2006-01-02 2006-01-01 2006-01-02 2006-01-01 0 7 9 6
2 2006-01-03 2006-01-01 2006-01-02 2006-01-01 0 13 12 4
3 2006-01-04 2006-01-01 2006-01-02 2006-01-01 0 13 15 4
4 2006-01-05 2006-01-01 2006-01-02 2006-01-01 0 20 6 3
5 2006-01-06 2006-01-01 2006-01-02 2006-01-01 0 19 19 4
6 2006-01-07 2006-01-01 2006-01-02 2006-01-01 0 4 16 5
For a single variable I used the next line of code:
ggplot(data = Full.df, aes(Month, Count.S)) + stat_summary(fun.y = sum, geom ="line") + scale_x_date(
labels = date_format("%m-%y"),
breaks = "3 months")
I would like to plot Count.S
, Count.G
, Count.W
, Count.F
as four lines on the same plane, but I can't figure out how to plot all four variables in ggplot
(or any other package for that matter). Thanks.
EDIT: While the link provided to a different question is incredibly useful, the answer there explains how to plot different graphs in one image. However, I was wondering how to plot lines corresponding to various variables in a single XY axis.
Two ways of doing this:
If sample data created as follows:
Optimal way using reshape2 package:
Alternative using multiple geoms but no legend: