ggplot2:删除x轴上的小刻度,但保持主要刻度

时间:2017-03-08 19:49:33

标签: r ggplot2 axis labels

我从ggplot2的以下R代码开始(取自https://stackoverflow.com/a/39724176稍作修改):

<div class="div1">
  <div class="div2">
    <img src="http://www.dailyrecoverymeditations.com/forums/image.php?u=2057&dateline=1404850818" style="float:right; padding-left: 10px;"> Testing Text Testing Text Testing Text Testing Text Testing Text Testing Text Testing Text Testing</div>
</div>

我想隐藏(某些)x轴上的刻度线。我知道,这可以通过使用:

来完成
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

但我想只隐藏次要刻度(在&#34; minor_breaks&#34;中指定),但不是主要刻度。有没有办法只隐藏次要刻度和/或指定要显示哪些次要/主要刻度?哪种不显示?

0 个答案:

没有答案