我正在尝试删除线条图例,但我不知道为什么它无法删除,我只想保留“supp”的点。
library(ggpubr)
a<-ggline(ToothGrowth, x = "dose", y = "len",
add = c("mean_se", "jitter"),
color = "supp", palette = "jco")
b<-ggline(ToothGrowth, x = "dose", y = "len",
add = c("mean_se", "jitter"),
color = "supp", palette = "jco")
ggarrange(plot_grid(a + theme(legend.position="none")), b,common.legend = TRUE, labels = c("A", "B"),legend = "right")
最佳答案
如果您想从图例中删除线条并保留点,您可以使用guides
并覆盖linetype
,如下所示:
library(ggpubr)
#> Loading required package: ggplot2
ggline(ToothGrowth, x = "dose", y = "len",
add = c("mean_se", "jitter"),
color = "supp", palette = "jco") +
guides(color = guide_legend(override.aes = list(linetype = 0)))
创建于 2022 年 11 月 25 日,使用 reprex v2.0.2
评论代码:
library(ggpubr)
library(cowplot)
a<-ggline(ToothGrowth, x = "dose", y = "len",
add = c("mean_se", "jitter"),
color = "supp", palette = "jco")
b<-ggline(ToothGrowth, x = "dose", y = "len",
add = c("mean_se", "jitter"),
color = "supp", palette = "jco")
ggarrange(plot_grid(a + theme(legend.position="none")),
b + guides(color = guide_legend(override.aes = list(linetype = 0))),
common.legend = TRUE,
labels = c("A", "B"),
legend = "right")
创建于 2022 年 11 月 25 日,使用 reprex v2.0.2
关于r - 如何删除图例中的线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74570360/