Skip to content

Instantly share code, notes, and snippets.

@bds
Created December 30, 2010 14:27
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bds/759838 to your computer and use it in GitHub Desktop.
Save bds/759838 to your computer and use it in GitHub Desktop.
Sample sparkline plot using ggplot
library(ggplot2)
sparkLinePlot <- function(df, plot.file) {
highest <- subset(df, outcomes == max(outcomes))
lowest <- subset(df, outcomes == min(outcomes))
p <- ggplot(df, aes(x=date, y=outcomes)) +
geom_line() +
opts(panel.border = theme_rect(linetype = 0),
panel.background = theme_rect(colour = "white"),
panel.grid.major = theme_blank(),
panel.grid.minor = theme_blank(),
axis.text.x = theme_blank(),
axis.text.y = theme_blank(),
axis.ticks = theme_blank()) +
ylab("") +
geom_point(data = lowest, size = 3, colour = alpha("red", 0.5)) +
geom_point(data = highest, size = 3, colour = alpha("blue", 0.5)) +
scale_y_continuous(formatter = comma) +
scale_x_date(name = "", major="months", minor="weeks", format="%b-%d")
ggsave(file = paste(plot.file, ".svg", sep=""), width = 3, height = 2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment