如何避免图例中出现彩色框?我希望它是 Line1
和 Line2
没有盒子。
library(ggplot2)
ggplot(diamonds, aes(x=depth)) +
geom_density(aes(color = "Line1"))+
geom_function(fun=function(x)
dnorm(x,
mean=mean(diamonds$depth),
sd=sd(diamonds$depth)),
aes(color="Line2"))+
scale_color_manual(" ", values=c(Line1="green", Line2="red"))
谢谢!
最佳答案
这可以通过将选项 show.legend = FALSE
添加到 geom_密度
来实现:
library(ggplot2)
ggplot(diamonds, aes(x=depth)) +
geom_density(aes(color = "Line1"), show.legend = FALSE)+
geom_function(fun=function(x)
dnorm(x,
mean=mean(diamonds$depth),
sd=sd(diamonds$depth)),
aes(color="Line2"))+
scale_color_manual(" ", values=c(Line1="green", Line2="red"))
关于r - 避免图例中的彩色框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64372128/