r - 调整构面图的宽度,facet_wrap
问题描述
我可以增加构面图的整体宽度以使所有标签都适合吗?或者有什么方法可以防止标签与另一个重叠?
mydata2 <- temperature %>% filter(month == 1 )
mydata2 %>% ggplot(aes(x = year , y = mean_max , color = station_name)) +
geom_jitter() +
facet_wrap(~station_name)
[
解决方案
一些选项:
- 旋转 x 轴标签:
ggplot() +
theme(axis.text.x = element_text(angle = 45))
- 移动图下方的图例,为刻面创造更多空间:
ggplot() +
theme(legend.position = "bottom")
然后,您还可以决定要在两列中使用以下图例:
ggplot() +
guides(color = guide_legend(ncol = 2))
- 您可以使用正确的大小将 ggplot 保存为 pdf/png
ggsave