且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从ggplot2中的x轴删除空白行

更新时间:2023-11-26 13:05:46

如果将direc转换为水平c('B', 'A')的因数(以左侧的B排列构面),

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"))

仅用facet_grid替换facet_wrap即可达到目的.

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')

好吧, a 技巧;希望这就是您想要的:

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

colour自变量在技术上也不需要这种安排,尽管它不会引起任何问题.我也删除了scale_x_continuous,因为它被scales = 'free'覆盖.

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'.