Spacing of discrete axis by a categorical variable

后端 未结 1 1455
星月不相逢
星月不相逢 2021-01-15 06:40

I have a categorical axis where i\'d like to visually separate groups within that categorical variable. I don\'t want to facet because it takes up too much space and is visu

相关标签:
1条回答
  • 2021-01-15 07:18

    You can get the result you are looking for via the breaks and limits arguments to scale_x_discrete. Set the breaks to the levels of the factor on the x-axis and the limits to the factor levels with spacers were you want/need them.

    Here is an example:

    library(ggplot2)
    
    dd <- data.frame(x = factor(letters[1:10]), y = 1:10)
    
    ggplot(dd) +
      aes(x = x, y = y) +
      geom_point() +
      scale_x_discrete(breaks = levels(dd$x),
                       limits = c(levels(dd$x)[1], "skip", levels(dd$x)[-1]))
    

    0 讨论(0)
提交回复
热议问题