Created
August 18, 2011 20:17
-
-
Save ramnathv/1155074 to your computer and use it in GitHub Desktop.
Monthplot with 3 Series
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(ggplot2) | |
require(lubridate) | |
# df is the data frame on the page http://goo.gl/MvG02 in the answer by Andrie | |
# this solution modifies his approach to allow multiple time series to be | |
# incorporated into the month plot | |
df = transform(df, values2 = values + 100, values3 = values + 200) | |
dfm = melt(df, id = 'dates') | |
dfm$month <- factor(month(dfm$dates), levels=1:12, labels=month.abb, ordered=TRUE) | |
dfm$year <- year(dfm$dates) | |
hline.data <- ddply(dfm, .(month, variable), summarize, avgvalue=mean(value)) | |
p0 = ggplot(dfm, aes(x = year, y = value, colour = variable)) + | |
geom_line() + | |
geom_hline(data = hline.data, aes(yintercept = avgvalue, colour = variable), size=2) + | |
facet_grid(. ~ month) + | |
opts(axis.text.x = theme_blank()) + | |
xlab("") | |
print(p0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment