Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Custom breaks and labels are missing on date axis

$
0
0

I have a scatterplot, made using ggplot, with dates on the x-axis (covering 8 weeks) and random points. I want a vertical line in the middle at a test date, and markers every 2 weeks (forward and back). Below is a minimum working example.

I have specified breaks and labels as per http://www.sthda.com/english/wiki/ggplot2-axis-ticks-a-guide-to-customize-tick-marks-and-labels.

But they do not appear...

Test = '2010-05-02'
data = data.frame(x=-28:28)
data$date = as.Date(Test)+data$x
data$y = sample(1:6, size=57, replace=TRUE)

ggplot(data) +
  geom_point(aes(date, y, color=y), alpha=0.45, size=1.2) +
  geom_vline(xintercept=as.Date(Test), color = '#0B50EF', linetype='twodash', size = 0.70) +
  theme_bw(7) + 
  theme(legend.position = "none") +  
  xlab('') +
  ylab('') +
  scale_x_discrete(breaks=c(as.Date(Test)-28,as.Date(Test)-14,as.Date(Test),as.Date(Test)+14,as.Date(Test)+28), 
                   labels=c(as.Date(Test)-28,as.Date(Test)-14,as.Date(Test),as.Date(Test)+14,as.Date(Test)+28))

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>