plot - R + ggplot2: how to hide missing dates from x-axis? -
say have following simple data-frame of date-value pairs, dates missing in sequence (i.e. jan 12 thru jan 14). when plot points, shows these missing dates on x-axis, there no points corresponding dates. want prevent these missing dates showing in x-axis, point sequence has no breaks. suggestions on how this? thanks!
dts <- c(as.date( c('2011-01-10', '2011-01-11', '2011-01-15', '2011-01-16'))) df <- data.frame(dt = dts, val = seq_along(dts)) ggplot(df, aes(dt,val)) + geom_point() + scale_x_date(format = '%d%b', major='days')
turn date data factor then. @ moment, ggplot interpreting data in sense have told data in - continuous date scale. don't want scale, want categorical scale:
require(ggplot2) dts <- as.date( c('2011-01-10', '2011-01-11', '2011-01-15', '2011-01-16')) df <- data.frame(dt = dts, val = seq_along(dts)) ggplot(df, aes(dt,val)) + geom_point() + scale_x_date(format = '%d%b', major='days')
versus
df <- data.frame(dt = factor(format(dts, format = '%d%b')), val = seq_along(dts)) ggplot(df, aes(dt,val)) + geom_point()
which produces:
is wanted?
Comments
Post a Comment