假代碼:
library(ggplot2)
library(patchwork)
plot1 <- mpg %>% ggplot()
plot2 <- mpg %>% ggplot()
plot3 <- mpg %> % ggplot(aes(cyl, displ))
geom_point(aes(colour=) 運算子">=制造商))
guides(colour=guide_legend(ncol=4))
(plot1 plot2) / plot3
我不是在尋找一個合并的圖例,而是尋找像這樣的東西:
在這里,圖例被 "視為 "繪圖的一部分。我已經嘗試用theme()和plot_spacer()添加邊距,但這并不是我想要的。
uj5u.com熱心網友回復:
對于你的示例代碼,一個選項是使用guide_area(),像這樣:
library(ggplot2)
library(patchwork)
library(magrittr)
plot1 <- mpg %>% ggplot()
plot2 <- mpg %>% ggplot()
plot3 <- mpg %> % ggplot(aes(cyl, displ))
geom_point(aes(colour=) 運算子">=制造商))
guides(colour = guide_legend(ncol=3))
plot1 plot2 plot3 運算子"> guide_area()
plot_layout(guides = 'collect')

另一個選擇是通過cowplot::get_legend提取指南,然后像這樣把它添加到補丁中:
(plot1 plot2) / (plot3 指導(color = "none") cowplot。 :get_legend(plot3))

創建于2021-09-22,由reprex包(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/334038.html
標籤:

