[英]Conditionally coloring data points based on a 3rd parameter with plot function in R
I am new to using R, and I am trying to make a scatterplot, which selectively will color data points based on a third parameter.我是使用 R 的新手,我正在尝试制作一个散点图,它会根据第三个参数有选择地为数据点着色。
My y variable is PR staining, and my x variable is ER staining.我的 y 变量是 PR 染色,我的 x 变量是 ER 染色。 I seek to color the data pts red which satisfy pcr=1;我试图将满足 pcr=1 的数据点着色为红色; all the other data pts should be black.所有其他数据点都应该是黑色的。 pcr is a separate column in my dataset. pcr 在我的数据集中是一个单独的列。
ERPR_plot <-- plot(mint$er_pct,mint$pr_pct,
xlab="ER Staining (%)",
ylab="PR Staining (%)",
xlim=range(0:100),
ylim=range(0:100),
main = "PR Percent Staining vs. ER Percent Staining",
col = ifelse(mint$pcr = 1,'red','green'))
Error: unexpected '=' in:
" main = "PR Percent Staining vs. ER Percent Staining",
col = ifelse(mint$pcr ="
Please help.请帮忙。 I've been searching threads for hours:)我已经搜索了几个小时的主题:)
Here, we are using the assignment ( =
) instead of comparative operator ( ==
) in ifelse
test
argument which based on the documentation of ?ifelse
is在这里,我们在ifelse
test
参数中使用赋值( =
)而不是比较运算符( ==
),它基于?ifelse
的文档是
test - an object which can be coerced to logical mode.测试 - 可以强制转换为逻辑模式的 object。
ifelse(mint$pcr == 1,'red','green'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.