0

I'm creating a line graph with ggplot that makes use of breaks to display only some of the labels. The issue is when I do that, the non-labeled tick marks and more importantly, the grid lines associated with those tick marks disappear. I really need the grid lines to remain. The tick marks staying would be nice, but not essential.

The code below will produce a graph that shows what I'm dealing with.

Thanks!

count<-c(1,5,6,8,3)
period<-c(1,2,3,4,5)

df<-data.frame(count,period)

library('ggplot2')
ggplot(data=df, aes(x = period, y =count ,group=1)) +
  geom_line(size=1)+
  scale_x_discrete(breaks=c(1,3,5),
                   labels=c("One",'Two','Three'))
rawr
  • 20,481
  • 4
  • 44
  • 78
Mark Romano
  • 701
  • 3
  • 12
  • 25
  • Check out http://stackoverflow.com/questions/14490071/adding-minor-tick-marks-to-the-x-axis-in-ggplot2-with-no-labels – steveb Feb 23 '16 at 17:23
  • 2
    There may be a bug in the code on the link I included, but I don't have time to confirm (it should be easily fixable if it isn't correct). This `scale_x_discrete` example is roughly what you may want: `scale_x_discrete(breaks=c(1:5), labels=c('One', '','Three', '','Five'))`. This is not a general solution but a simple example. – steveb Feb 23 '16 at 17:46
  • Helpful hack. Thanks! – Mark Romano Feb 23 '16 at 18:06
  • 1
    Yes, it is a hack, I wish it were an option in ggplot. – steveb Feb 23 '16 at 19:37
  • @steveb I agree....Seems like a no-brainer option to have....thanks again! – Mark Romano Feb 24 '16 at 18:20

0 Answers0