如何在R中的多面图中添加缺失的x轴

时间:2016-09-12 08:02:10

标签: r ggplot2

我有一个名为cpp的数据框。我在下面的两个图中绘制了下图中缺少X轴的图。如何将x轴放在这两个图上?另外,我还想增加每个盒子的大小,这样线条就不会碰到右边的边缘。

ggplot(cpp, aes(x = Num_Good, y = IBS, group = key.related.sheet, color = cutoff)) +
  geom_line() + facet_wrap(~cutoff) + geom_point()

enter image description here

1 个答案:

答案 0 :(得分:2)

查看关于"悬挂"的答案方面:add "floating" axis labels in facet_wrap plot

或者作为快速解决方法(如果可以将x轴添加到所有构面),您可以设置scales = "free_x"的参数facet_wrap

关于问题的第二部分,请尝试在expand中设置scale_x_continuous参数的第二个值,例如:

ggplot(cpp, aes(x = Num_Good, y = IBS, group = key.related.sheet, color = cutoff))+
  geom_line() + 
  facet_wrap(~cutoff, scales = "free_x") + 
  geom_point() +
  scale_x_continuous(expand = c(0, .1))