r - 图中的颜色点根据值向量的不同而不同

标签 r colors plot gradient

我正在使用 R 的 plot() 函数绘制下图。它是时间平移向量 shiftTime 的绘图。我有另一个强度值的矢量强度,范围从 ~3 到 ~9。我想根据具有颜色渐变的这些值对图中的点进行着色。在这些示例中,我可以在实际绘制点的值上找到颜色,因此在本例中为向量 shiftTime 的值。只要相应的值位于同一索引上,是否也可以使用不同的向量?

plot

最佳答案

这是使用基本 R 图形的解决方案:

#Some sample data
x <- runif(100)
dat <- data.frame(x = x,y = x^2 + 1)

#Create a function to generate a continuous color palette
rbPal <- colorRampPalette(c('red','blue'))

#This adds a column of color values
# based on the y values
dat$Col <- rbPal(10)[as.numeric(cut(dat$y,breaks = 10))]

plot(dat$x,dat$y,pch = 20,col = dat$Col)

enter image description here

关于r - 图中的颜色点根据值向量的不同而不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9946630/

相关文章:

r - .wav 文件长度/持续时间,无需读取文件

r - 为 ggplot 图例动态创建表达式?

RMarkdown - print() 命令导致套件 PDF 中的页面绑定(bind)线超出页面范围

colors - glTF - 设置颜色 - baseColorFactor

r - "axis"不会将 x Axis 添加到箱线图

r - R 中的文本分析 : How to add variables to my machine learning classifier in addition to the tokens?

ios - 我可以发布包含半透明项目的应用程序吗?

php - 如何调整颜色背景的大小

matlab - 当 x 轴是时间时,如何在绘图上绘制彩色矩形?

r - ggplot2:如何按颜色将图例拆分为自定义图例