设置向量在R中的颜色缩放 [英] set color scaling of a vector in R
本文介绍了设置向量在R中的颜色缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我选择的颜色标度上取0和1之间的数值的向量。现在我可以得到控制,当有两种颜色与下面的代码。
library(plotrix)
set.seed(1)
x< - sort ,min = 0,max = 1))
redsNblues < - color.scale(x,extremes = c(#ff0000,#0000ff))
plot(x,col = redsNblues)
但是,如果我想从蓝色变成红色,那么我该如何做到这一点呢?
解决方案
library(plotrix)
/ pre>
set.seed(1)
x< - sort(runif(10,min = 0,max = 1))
#创建一个颜色函数,它将返回我们想要的范围内的颜色
colorfunc = colorRamp c(blue,white,red))
#使用colorfunc创建范围从蓝色到白色到红色的颜色
#跨越x
mycolors = rgb(colorfunc(x),maxColorValue = 255)
plot(x,col = mycolors,pch = 16,cex = 3)
>
I would like to take a vector of numerical values between 0 and 1 over a color scale of my choice. Right now I can get control when there are two colors with the code below.
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)
But how would I do this elegantly if I wanted to go from blue to red with white in between?
解决方案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)
这篇关于设置向量在R中的颜色缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文