0

I'm starting with the following R code for ggplot2 (taken from https://stackoverflow.com/a/39724176 with minor modifications):

lims = c(0,100)

breaks.major <- c(0,15,37.5,52.5,67.5,82.5,95) #defines the midpoints of the categories (label locations)
breaks.minor <- c(30,45,60,75,90,100)   #defines the edges of the categories (second label set I need)

breaks.comb <- sort(c(breaks.major2, breaks.minor2 - 1.0E-6))  # avoid the just same value as minor
label.comb <- c(0, "\nExtremely \nDissatisfied", 30, "\nDissatisfied", 45, "\nUncertain", 60, 
                "\nSatisfied", 75, "\nVery \nSatisfied", 90, "\nExtremely \nSatisfied", 100)

library(ggplot2)
g <- ggplot(mpg, aes(class))+
  geom_bar()+
  coord_flip()+
  scale_y_continuous(limit = lims, minor_breaks = breaks.minor, breaks = breaks.comb, 
                     labels = label.comb, expand = c(0,0)) +
  theme(panel.grid.major.x = element_blank()) +
  theme(panel.grid.major.y = element_blank()) +
  #theme(axis.ticks.x=element_blank()) + #Hides ALL ticks!
  theme(axis.title= element_blank()) +
  theme(plot.margin = unit(c(0.5, 0.5, 0.5, 0.5), "lines"))
g

I would like to hide (some of) the ticks on the x axis. I'm aware, that this can be done by using:

theme(axis.ticks.x=element_blank())

but I would like to hide only the minor ticks (as specified in "minor_breaks"), but not the major ticks. Is there a way to only hide the minor ticks and/or specify which minor/major ticks are to be shown and which not?

Community
  • 1
  • 1
user6475
  • 31
  • 1
  • 11
  • I'm confused, doesn't [cuttlefish's answer at the question you link](http://stackoverflow.com/a/39724176/903061) do exactly what you want? – Gregor Thomas Mar 08 '17 at 20:28
  • Oh, I see - cuttlefish's answer gets rid of all the tick marks. `ggplot` doesn't distinguish between major and minor tick marks (minor breaks don't get tick marks, which is why your code uses `breaks = breaks.comb`, not `breaks = breaks.major`). I think to get the tick marks and the extra labels you'll have to do something like hrbrmstr's answer which should work fine if you omit the `axis.ticks.x=element_blank()` line. – Gregor Thomas Mar 08 '17 at 20:37
  • @Gregor thank you for the quick answer! Hmmm, I tried @hrbrmstr's answer, but 1) I don't manage to reproduce his figure with his code (the values of the second axis are not shown) - Can you confirm this? 2) When I omit: a) `gg1 <- gg1 + theme(axis.ticks.x=element_blank())` the "minor ticks" (i. e. the ticks for the category labels) are shown, but not the "major ones" (i. e., the ones for the values) b) `gg2 <- gg2 + theme(axis.ticks.x=element_blank())` all ticks are missing – user6475 Mar 09 '17 at 09:46
  • Furthermore, I was hoping I could use @cuttlefish's answer, as it has less dependencies (my actual figure is way more complex and relies on a package that is derived from ggplot2). If, however, this is the only solution (given that issue 1 and 2 can be solved), I will try to implement hrbrmstr's answer for my setting. Thank you for your help! – user6475 Mar 09 '17 at 09:47

0 Answers0