Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
scale_x_date limits not subsetting data #1090
Posted on Stack Overflow:
I've noticed that scale_x_date is displaying data outside of the limits specified in the scale. See example below. Why am I seeing points before 2009/01/01 and after 2015/01/01 in the graph if the limits are set to these values?
Just to be clear, the limits of the scales are controlled by the expand parameter, but the limits of the data should not be affected. At least this is the behavior when using scale_x_continuous. Currently scale_x_date is functioning differently than scale_x_continuous.
Here's a somewhat simpler reproducible example:
library(ggplot2) df <- data.frame( x = as.Date("2000-01-01") + 0:50, y = 1, z = 0:50 ) ggplot(df, aes(x, y, colour = z >= 1)) + geom_point() ggplot(df, aes(x, y, colour = z >= 1)) + geom_point() + scale_x_date(limits = c(df$x[], NA)) ggplot(df, aes(as.numeric(x), y, colour = z >= 1)) + geom_point() + scale_x_continuous(limits = c(df$x[], NA))