使用条件语句更改数据点的颜色 [英] Using Conditional Statements to Change the Color of Data Points
问题描述
我有一个数据集,我用来做一个散点图,我想根据它们的x值,为三个不同区域内的数据点分配三种不同的颜色。
I have a data set, which I have used to make a scatter plot and I would like to assign three different colors to the data points within three different regions, based on their x values.
具有x值的数据点< 3我想出现红色
Data points with x-values < 3 I want to appear red
数据点与x值(3,1549)我想显示为黑色
Data points with x-values (3,1549) I want to appear black
数据点x值> 1549我想显示紫色
Data points with x values >1549 I want to appear purple
这是我的散点图的代码,并完成前两个参数,我如何实现第三个参数,这样最后一个区域的数据点将是紫色的?
Here is my code for the scatterplot and accomplishing the first two parameters, how might I implement the third parameter, so that the last region's data points will be purple?
plot(x, y, xlab="chr X position (Mb)",
ylab="Diversity",
pch=16, cex =0.7,
col = ifelse(x < 3,'red','black'))
>
推荐答案
只需使用嵌套 ifelse
s:
plot(...., col=ifelse(x < 3, "red", ifelse(x > 1549, "purple", "black")))
这篇关于使用条件语句更改数据点的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!