使用R的patchwork包布局绘图时图例未显示的问题
问题:patchwork布局中图例缺失,无法在指定位置显示
我尝试用patchwork的guide_area()和plot_layout(guides = "collect")来把共享图例放在指定的guide space中心位置,但图例却不见了。我期望图例出现在下图红色问号所在的位置(两个绘图区域上方的中心区域)。
library(ggplot2) library(patchwork) # 创建四个带共同图例的示例图,先隐藏各自图例 p1 <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) + geom_point() + theme(legend.position = "none") p2 <- ggplot(mtcars, aes(x = hp, y = mpg, color = factor(cyl))) + geom_point() + theme(legend.position = "none") p3 <- ggplot(mtcars, aes(x = qsec, y = mpg, color = factor(cyl))) + geom_point() + theme(legend.position = "none") p4 <- ggplot(mtcars, aes(x = disp, y = mpg, color = factor(cyl))) + geom_point() + theme(legend.position = "none") # 定义布局模板 design2 <- " ABC DEE " # 组合绘图并设置布局 p1 + p2 + p3 + p4 + guide_area() + plot_layout(guides = "collect", widths = c(5, 5, 5), heights = c(5, 5), design = design2)

内容的提问来源于stack exchange,提问作者Giuseppe Petri
相关产品推荐
相关产品推荐

