繁体   English   中英

在ggplot2中以自定义颜色显示图例

[英]Show legend with custom colors in ggplot2

我有一列带有颜色代码的列,但是使用它们时我看不到任何图例。

例:

library(ggplot2)

iris$col = rep(c('#b580d1', '#9bb240', '#6a70d7'), each = 50)

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color = iris$col)) +
  geom_line() +
  geom_point() +
  scale_color_identity()

我想拥有相同的图例,但具有与以下不同的颜色:

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
  geom_line() +
  geom_point()
library(ggplot2)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
  geom_line() +
  geom_point() +
  scale_color_manual(values= c('#b580d1', '#9bb240', '#6a70d7'))

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM