I want to produce one plot comparing data obtained in different years. The goal is having 12 months on the x axis and drawing different lines with the values for each of the years.
The data frame I'm using is the next one:
Month Marg Fiscal.Year
1 2009-04-01 20904494 2009
2 2009-05-01 43301981 2009
3 2009-06-01 14004552 2009
...
38 2012-05-01 58343271 2012
39 2012-06-01 38723765 2012
40 2012-07-01 77246753 2012
My code of the plot is:
g <- ggplot(data = data, stat="identity", aes(x = Month, y = Marg)) +
geom_line() +
geom_point() +
geom_smooth(method = "loess") +
scale_x_date(breaks = "1 month", labels = date_format("%b"));
but this plots in the x axis 48 months from 2009 to 2012, and one line in it showing each of the values (not different lines for each year for each of the months).
Could you please help me solving this issue? (I'm new with R, any help will be appreciated).
Thanks in advance for your answer!