问题描述
我正在使用 R 的 plot()
函数绘制下图.它是时间偏移向量 shiftTime
的图.我有另一个矢量 intensity
的强度值,范围从 ~3 到 ~9.我想根据具有颜色渐变的值为图中的点着色.我可以在实际绘制点的值上找到颜色的示例,因此在这种情况下是矢量 shiftTime
的值.是否也可以使用不同的向量,只要相应的值在同一个索引上?
I'm plotting the figure below using R's plot()
function. It is a plot of a vector shiftTime
of shift in time. I have another vector intensity
of the intensity values ranging from ~3 to ~9. I want to color my points in the plot based on those values with a color gradient. The examples I can find color on the value of the actual plotted points, so in this case the values of the vector shiftTime
. Is it also possible to use a different vector, as long as the corresponding values are on the same index?
推荐答案
这是使用基本 R 图形的解决方案:
Here's a solution using base R graphics:
#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)
这篇关于绘图中的颜色点因值向量而异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!