Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created August 18, 2011 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramnathv/1155074 to your computer and use it in GitHub Desktop.
Save ramnathv/1155074 to your computer and use it in GitHub Desktop.
Monthplot with 3 Series
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