Remove blank lines from x axis in ggplot2

后端 未结 2 461
[愿得一人]
[愿得一人] 2021-01-15 00:26

I have a some trouble about removing the space in between x axis values. I want to remove the gap between two values in each facet_wrap

I checked this

2条回答
  •  孤街浪徒
    2021-01-15 00:54

    If you turn direc into a factor with levels c('B', 'A') (to arrange facets with B on the left),

    df$direc <- factor(direc, levels = c("B", "A"))
    

    just replacing facet_wrap with a facet_grid does the trick.

    ggplot(data = df, aes(x = x, y = yy, colour = direc)) +
      geom_point(size=5)+
      geom_line(size=1.3)+
      scale_y_log10(limits = c(1e-7,1),breaks = c(3e-7,1e-3,1e-1,1))+
      facet_grid(add ~ direc, scales = 'free')
    

    Well, a trick; hopefully it's what you want:

    The colour argument is also technically unnecessary with this arrangement, though it doesn't cause any issues. I took out scale_x_continuous, as well, because it gets overridden by scales = 'free'.

提交回复
热议问题