简体   繁体   English

散点图子集颜色形状ifelse

[英]Scatter plot points subset colour shape ifelse

I'd like to do a scatter plot where some of the values, out of a subset, are plotted differently in colour and shape. 我想做一个散点图,其中子集中的某些值在颜色和形状上的绘制方式不同。 I've worked around the following code but I don't manage to make it right. 我已经解决了以下代码,但是我没有做到正确。 Any help greatly appreciated! 任何帮助,不胜感激!

# My data
iris
iris$Code <- 1:150

# A selection of my data I'd like to plot differently
subset <- subset(iris, iris$Sepal.Width<3.5)
sel <- as.character(subset$Code) # I think the problems start here :)

# Plotting doesn't work
plot(iris$Sepal.Length ~ iris$Sepal.Width,
     col=ifelse(iris$Code==sel, "red", "black"),
     pch=ifelse(iris$Code==sel, 17, 1))

Try this: 尝试这个:

#define subset
sel <- iris[iris$Sepal.Width<3.5,"Code"]
#plot
plot(iris$Sepal.Length ~ iris$Sepal.Width,
     col=ifelse(iris$Code %in% sel, "red", "black"),
     pch=ifelse(iris$Code %in% sel, 17, 1))

Note: in your code there are some obvious mistakes: 注意:在您的代码中有一些明显的错误:

dd <- iris - why assign to dd and never use it? dd <- iris为什么分配给dd而不使用它?

iris$Sepal.Widith - spelling iris$Sepal.Widith拼写

... "black") - comma missing at the end. ... "black") -末尾缺少逗号。

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

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