如何根据颜色的特定要求进行散点图绘制?

时间:2018-07-28 05:10:26

标签: r scatter-plot

colored = c('red','blue','yellow')
plot(iris$Petal.length,iris$Petal.Width)

我试图绘制iris $ Pedal.width和iris $ Pedal.length,并希望颜色跟随花朵的种类(有3种'setosa','versicolor','Virginia')

我创建一个颜色矢量,我希望所有的setosa为红色,所有的杂色为蓝色,所有的Virginia为黄色。如何在plot(iris $ Pedal.width,iris $ Pedal.length)中使用颜色矢量来实现此目标?

1 个答案:

答案 0 :(得分:2)

使用ggplot而非plot解决方案如何?

library(ggplot2)

ggplot(data = iris, aes(Petal.Length, Petal.Width, color = Species)) +
  geom_point() +
  scale_color_manual(values = c("setosa" = "red", "versicolor" = "blue", "virginica" = "yellow"))
相关问题