Skip to content

Instantly share code, notes, and snippets.

@kohske
Created December 13, 2011 12:13
Show Gist options
  • Save kohske/1471921 to your computer and use it in GitHub Desktop.
Save kohske/1471921 to your computer and use it in GitHub Desktop.
Multi years calendar by R and ggplot2
library(ggplot2)
f <- function(y1, y2) {
d <- seq.Date(as.Date(paste(y1, "-01-01", sep = "")), as.Date(paste(y2, "-12-31", sep = "")), "day")
z <- data.frame(
D = as.numeric(format(d, "%d")),
W = format(d, "%w"),
M = as.numeric(format(d, "%m")),
Y = format(d, "%Y"))
ggplot(z, aes(D, M, fill = W)) +
geom_tile(colour = "grey20", alpha = 0.75) +
facet_grid(Y~.) +
scale_y_continuous(trans = "reverse", breaks = 1:12) +
scale_fill_manual(values = c("skyblue", rep("white", 5), "aquamarine")) +
opts(legend.position = "none", axis.title.x = theme_blank(), axis.title.y = theme_blank(), panel.margin = unit(0.1, "lines"))
}
f(2012, 2015)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment