如何避免使用ggarrange时轴线消失?

如何避免使用ggarrange时轴线消失?,r,ggplot2,facet,R,Ggplot2,Facet,我想使用ggarrange排列两个刻面图(以使x轴对齐) 库(egg) 图书馆(GG2) p1tl;dr:设置panel.background=element\u blank()应恢复轴。 我认为这是ggplot2中的剪切问题(y轴线可以被绘图面板剪切,将其宽度减半)和将轴放置在绘图面板下方的egg::gtable_框架的组合 library(egg) library(ggplot2) p1 <- ggplot(warpbreaks) + geom_bar(aes(x = wool)

我想使用
ggarrange
排列两个刻面图(以使x轴对齐)

库(egg)
图书馆(GG2)

p1tl;dr:设置
panel.background=element\u blank()
应恢复轴。

我认为这是ggplot2中的剪切问题(y轴线可以被绘图面板剪切,将其宽度减半)和将轴放置在绘图面板下方的egg::gtable_框架的组合

library(egg)
library(ggplot2)

p1 <- ggplot(warpbreaks) +
  geom_bar(aes(x = wool)) +
  facet_wrap(~tension, ncol = 2, scales = "free_x") +
  theme_bw() +
  theme(axis.line = element_line(colour = alpha("red", 0.5), size = 5),
        panel.border = element_blank(),
        panel.background = element_rect(fill = alpha("white", 0.5), 
                                        linetype = 2, colour = "black"),
        strip.background = element_blank())

p1
库(egg)
图书馆(GG2)

p1似乎与y轴线的剪裁问题有关;它不会完全消失,但有一半会被绘图面板剪掉。尝试添加
panel.background=element\u blank()
这会出现在原始
ggplot()。
library(egg)
library(ggplot2)

p1 <- ggplot(warpbreaks) +
  geom_bar(aes(x = wool)) +
  facet_wrap(~tension, ncol = 2, scales = "free_x") +
  theme_bw() +
  theme(axis.line = element_line(colour = alpha("red", 0.5), size = 5),
        panel.border = element_blank(),
        panel.background = element_rect(fill = alpha("white", 0.5), 
                                        linetype = 2, colour = "black"),
        strip.background = element_blank())

p1
g1 <- ggplotGrob(p1)
gg <- gtable_frame(g1)
grid.newpage()
grid.draw(gg)