重新调整r中的调色板

时间:2017-10-13 10:25:19

标签: r graphic

在R中我有一个零左右的数据云,有些数据在1左右,我想“重新调整”我的热色以区分较低的数字。这必须以彩虹的方式完成,我不想要“离散的颜色“。我尝试使用image.plot中的中断,但它不起作用。

lowerbreak=seq(min(values),quantile2,len=80)
  highbreak=seq(quantile2+0.0000000001,max(values),len=20)
  break=c(lowerbreak,highbreak)
  ii <- cut(values, breaks = break, 
            include.lowest = TRUE)

  colors <- colorRampPalette(c("lightblue", "blue"))(99)[ii]

我试过了:

13-Oct-2017 07:01:50.942 WARNING [http-nio-8080-exec-6] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://somevmserver:8080/rest/scriptrunner-jira/latest/listeners/com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener/params, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
13-Oct-2017 07:02:26.740 WARNING [http-nio-8080-exec-12] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://somevmserver:8080/rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.common.StaticCompilationChecker, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
13-Oct-2017 07:02:26.974 WARNING [http-nio-8080-exec-1] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://somevmserver:8080/rest/scriptrunner-jira/latest/listeners/com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener/preview, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

2 个答案:

答案 0 :(得分:2)

这是一种使用&#34;壁球&#34;图书馆。使用makecmap(),您可以指定颜色值和中断,还可以指定使用base参数对其进行日志拉伸。它有点复杂,但可以为您提供精细控制。我用它来为偏斜的数据着色,我需要更多的定义在&#34;低端&#34;。

为了实现彩虹调色板,我使用了内置的&#34; jet&#34;颜色功能,但您可以使用任何颜色集 - 我举例说明使用&#34; colorRampPalette&#34;创建灰度渐变。

无论您使用什么样的渐变,都需要使用base值来优化您的数据。

install.packages("squash")
library("squash")

#choose your colour thresholds - outliers will be RED
minval=0   #lowest value to get a colour
maxval=2.0 #highest value to get a colour
n.cols=100 #how many colours do you want in your palette?
col.int=1/n.cols

#create your palette
colramp=makecmap(x=seq(minval,maxval,col.int),
                 n=n.cols,
                 breaks=prettyLog,
                 symm=F,
                 base=10,#to give ramp a log(base) stretch
                 colFn=jet,
                 col.na="red",
                 right=F,
                 include.lowest=T)

# If you don't like the colFn options in "makecmap", define your own!
#   Here's an example in greyscale; pass this to "colFn" above
user.colfn=colorRampPalette(c("black","white"))

在绘图中使用colramp的示例(假设您已经在程序中的某处创建了colramp):

varx=1:100
vary=1:100
plot(x,y,col=colramp$colors) #colors is the 2nd vector in the colramp list

要从列表中选择特定的颜色,通过例如颜色[1:20](如果你尝试使用上面的例子,第一种颜色将重复5次 - 不是很有用,但你得到的逻辑和能玩耍。)

在我的情况下,我有一个值网格,我想变成彩色光栅图像(即颜色映射一些连续数据)。以下是使用组合矩阵的示例代码:

#create a "dummy matrix"
matx=matrix(data=c(rep(2,50),rep(0,500),rep(0.5,500),rep(1,500),rep(1.5,500)),nrow=50,ncol=41,byrow=F)

#transpose the matrix
#  the output of "savemat" is rotated 90 degrees to the left
#  so savemat(maty) will be a colorized version of (matx)
maty=t(matx)

#savemat creates an image using colramp
savemat(x=maty,
    filename="/Users/KeeganSmith/Desktop/matx.png",
    map=colramp,
    outlier="red",
    dev="png",
    do.dev.off=T)

The resulting image of matx

答案 1 :(得分:1)

使用colorRampPalette时,您可以设置bias参数以强调低(或高)值。

colorRampPalette(heat.colors(100),bias=3)这样的内容会使焦点集中在&#39; ramp&#39;在较低的位置,帮助他们在视觉上更加明显。