首页 > 解决方案 > 避免传说中的彩色框

问题描述

如何避免传说中的彩色框?我只是希望它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"))

谢谢!

标签: rggplot2

解决方案


这可以通过添加选项show.legend = FALSE来实现geom_density

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"))


推荐阅读