Skip to content

Instantly share code, notes, and snippets.

@dholstius
Created November 27, 2012 20:46
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 dholstius/4156896 to your computer and use it in GitHub Desktop.
Save dholstius/4156896 to your computer and use it in GitHub Desktop.
Helpful scales for use with ggplot2
require(ggplot2)
require(scales)
seq_range <- function(x, by) seq(min(x), max(x), by=by)
time_breaks <- function(width) {
function(limits) seq_range(limits, by=width)
}
scale_x_hours <- function(
...,
breaks = date_breaks(width='1 hour'),
minor_breaks = time_breaks(width='15 mins'),
labels = date_format('%H:%M\n%a')
) {
scale_x_datetime(..., breaks=breaks, minor_breaks=minor_breaks, labels=labels)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment