我有一個系統發育樹,如下圖。

我確實制作了一個假資料框來獲取圖例,現在我想將該圖例插入到系統發育樹的中心。我使用過grid.arrange但我無法移動圖例位置。
我創造的虛假傳說
df <- data.frame(name = c("ANA-GRADE", "ASTERIDS","BASAL EUDICOTS", "BASAL SUPERASTERIDS",
"CHOLORANTHALES", "MAGNOLIIDS", "MONOCOTS","ROSIDS",
"ANA-GRADE", "ASTERIDS","BASAL EUDICOTS", "BASAL SUPERASTERIDS",
"CHOLORANTHALES", "MAGNOLIIDS", "MONOCOTS","ROSIDS"),
colour = c("#EFF13A", "#428d34", "#84cf70", "#62a852", "#CDD100",
"#8B5742", "#EEAD0E", "#2d7a21", "#EFF13A", "#428d34",
"#84cf70", "#62a852", "#CDD100", "#8B5742", "#EEAD0E", "#2d7a21"),
x1 = runif(16, 5,100),
y1 = runif(16, 20,50))
fake <- df %>% ggplot(aes(x1,y1, colour = name))
geom_line(size = 1)
scale_colour_manual(values = c("#EFF13A", "#428d34", "#84cf70", "#62a852", "#CDD100",
"#8B5742", "#EEAD0E", "#2d7a21"),
name = "Major clade")
theme_bw()
theme(legend.title = element_text(face = "bold",size = 12))
legend <- get_legend(fake)
# using grid.arrange
有沒有人建議我使用grid.arrange?
uj5u.com熱心網友回復:
新ggdraw功能 fromcowplot提供了一種選擇。
它接受任何 grob,而不僅僅是 ggplot 物件。
library(tidyverse)
library(cowplot)
df <- data.frame(name = c("ANA-GRADE", "ASTERIDS","BASAL EUDICOTS", "BASAL SUPERASTERIDS",
"CHOLORANTHALES", "MAGNOLIIDS", "MONOCOTS","ROSIDS",
"ANA-GRADE", "ASTERIDS","BASAL EUDICOTS", "BASAL SUPERASTERIDS",
"CHOLORANTHALES", "MAGNOLIIDS", "MONOCOTS","ROSIDS"),
colour = c("#EFF13A", "#428d34", "#84cf70", "#62a852", "#CDD100",
"#8B5742", "#EEAD0E", "#2d7a21", "#EFF13A", "#428d34",
"#84cf70", "#62a852", "#CDD100", "#8B5742", "#EEAD0E", "#2d7a21"),
x1 = runif(16, 5,100),
y1 = runif(16, 20,50))
fake <-
df %>% ggplot(aes(x1,y1, colour = name))
geom_line(size = 1)
scale_colour_manual(values = c("#EFF13A", "#428d34", "#84cf70", "#62a852", "#CDD100",
"#8B5742", "#EEAD0E", "#2d7a21"),
name = "Major clade")
theme_bw()
theme(legend.title = element_text(face = "bold",size = 12))
sample_donut_plot <-
data.frame() %>%
ggplot(aes(ymin = 0, ymax = 1, xmin = 3, xmax = 4), )
geom_rect()
coord_polar(theta="y")
xlim(c(0, 4))
theme_void()
legend <- cowplot::get_legend(fake)
cowplot::ggdraw(sample_donut_plot)
cowplot::draw_plot(legend, x = .25, y = .25, width = .5, height = .5)

由reprex 包(v2.0.1)于 2021 年 10 月 25 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/338259.html
