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') 

enter image description here

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: enter image description here

is wanted?


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -