在 R 中设置矢量的颜色比例
set color scaling of a vector in R
我想在我选择的色标上采用 0 到 1 之间的数值矢量。现在我可以通过下面的代码控制两种颜色。
library(plotrix)
set.seed(1)
x <- sort(runif(10, min = 0, max = 1))
redsNblues<- color.scale(x, extremes = c("#ff0000", "#0000ff"))
plot(x, col = redsNblues)
但是,如果我想从蓝色变为红色,中间夹带白色,我该如何优雅地做到这一点呢?
library(plotrix)
set.seed(1)
x <- sort(runif(10, min = 0, max = 1))
# Create a color function that will return colors in the range we want
colorfunc = colorRamp(c("blue","white","red"))
# Use colorfunc to create colors that range from blue to white to red
# across the range of x
mycolors = rgb(colorfunc(x), maxColorValue=255)
plot(x, col=mycolors, pch=16, cex=3)
我想在我选择的色标上采用 0 到 1 之间的数值矢量。现在我可以通过下面的代码控制两种颜色。
library(plotrix)
set.seed(1)
x <- sort(runif(10, min = 0, max = 1))
redsNblues<- color.scale(x, extremes = c("#ff0000", "#0000ff"))
plot(x, col = redsNblues)
但是,如果我想从蓝色变为红色,中间夹带白色,我该如何优雅地做到这一点呢?
library(plotrix)
set.seed(1)
x <- sort(runif(10, min = 0, max = 1))
# Create a color function that will return colors in the range we want
colorfunc = colorRamp(c("blue","white","red"))
# Use colorfunc to create colors that range from blue to white to red
# across the range of x
mycolors = rgb(colorfunc(x), maxColorValue=255)
plot(x, col=mycolors, pch=16, cex=3)