【问题标题】:R distinct some points with different colorR用不同颜色区分一些点
【发布时间】:2015-12-16 06:08:07
【问题描述】:

我的散点图中大约有 20.000 个点。我有一个有趣点的列表,并希望在散点图中用不同的颜色显示这些点。有什么简单的方法吗?谢谢。

进一步解释,

我有一个矩阵,由 20.000 行组成,比如 R1 到 R20000 和 4 列,比如 A、B、C 和 D。每一行都有自己的 row.names。我想在 A 和 C 之间绘制散点图。使用 plot(data$A,data$B) 很容易。

另一方面,我有一个 row.names 列表,我想检查这些点在散点图中的位置。比方说 R1,R3,R5,R10,R20,R25。

我只想改变散点图中 R1,R3,R5,R10,R20,R25 的颜色与其他点不同。对不起,如果我的解释不清楚。

【问题讨论】:

  • 请考虑展示一个可重现的小例子

标签: r scatter-plot


【解决方案1】:

如果您的数据是简单的形式,那么很容易做到。例如:

# Make some toy data
dat <- data.frame(x = rnorm(1000), y = rnorm(1000))

# List of indicies (or a logical vector) defining your interesting points
is.interesting <- sample(1000, 30) 

# Create vector/column of colours
dat$col <- "lightgrey"
dat$col[is.interesting] <- "red"

# Plot
with(dat, plot(x, y, col = col, pch = 16))

没有可重复的例子,很难说更具体的。

【讨论】:

  • 就是这样!我的数据就这么简单。
猜你喜欢
  • 2018-04-08
  • 1970-01-01
  • 1970-01-01
  • 2016-08-14
  • 1970-01-01
  • 1970-01-01
  • 2018-02-22
  • 1970-01-01
  • 2013-02-26
相关资源
最近更新 更多