无法将图例添加到多个geom_density层

时间:2019-05-09 19:14:36

标签: r ggplot2

我知道有人问过类似的问题,但是到目前为止,尝试解决这些问题似乎对我没有用。

我有以下内容:

ggplot(music2) +
  geom_density(aes(x = danceability), color = "red", fill = "red", alpha = 0.4) +
  geom_density(aes(x = energy), color = "purple", fill = "purple", alpha = 0.4) +
  geom_density(aes(x = valence), color = "green", fill = "green", alpha = 0.4) +
  labs(title = "Attributes of Top 20 Spotify Hits",
       x = "Amount of Attribute",
       y = "Frequency")

这给了我

enter image description here

我想要一个带有每个变量颜色的图例。我曾尝试在末尾添加以下内容:

 + scale_color_manual(values = c("red", "purple" , "green"), 
                      labels = c("Dance", "Energy", "Valence"))

但这并没有增加任何不同之处。任何建议,将不胜感激!

0 个答案:

没有答案