设置单个数据点的颜色 [英] Setting the color for an individual data point

查看:105
本文介绍了设置单个数据点的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在R的散点图中为单个数据点设置颜色?

How can I set the colour for a single data point in a scatter plot in R?

我正在使用plot

推荐答案

要扩展@Dirk Eddelbuettel的答案,可以在对plot的调用中对col使用任何函数.例如,这会将x==3点涂成红色,而其他所有点都涂成黑色:

To expand on @Dirk Eddelbuettel's answer, you can use any function for col in the call to plot. For instance, this colors the x==3 point red, leaving all others black:

x <- 1:5
plot(x, x, col=ifelse(x==3, "red", "black"))

点字符pch,字符扩展cex等也是如此

Same goes for point character pch, character expansion cex, etc.

plot(x, x, col=ifelse(x==3, "red", "black"),
     pch=ifelse(x==3, 19, 1), cex=ifelse(x==3, 2, 1))

这篇关于设置单个数据点的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆