How can I suppress the vertical gridlines in a ggplot2 plot while retaining the x-axis labels?

前端 未结 5 1087
轮回少年
轮回少年 2021-02-19 23:54

This is a follow-on from this question, in which I was trying to suppress the vertical gridlines.

The solution, as provided by learnr, was to add scale_x_continuous(brea

5条回答
  •  再見小時候
    2021-02-20 00:29

    As code in comments does not display nicely, so I am posting this as an answer. You could do something like this and add labels manually with geom_text():

    ggplot(data, aes(x, y)) +
            geom_bar(stat = 'identity') +
            scale_x_continuous(breaks = NA) +
            opts(
                    panel.grid.major = theme_line(size = 0.5, colour = '#1391FF'),
                    panel.grid.minor = theme_blank(),
                    panel.background = theme_blank(),
                    axis.ticks = theme_blank()
            )+
            geom_text(aes(label = x, y = -.3))
    

提交回复
热议问题