R 中的 image.plot 不显示色标边缘的色标值 [英] image.plot in R not displaying colorscale values at the edges of color scale

查看:58
本文介绍了R 中的 image.plot 不显示色标边缘的色标值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[

注意两个图像上色标标签的差异.顶部图像是 R 3.2.5 的输出,相同的代码在 R 2.15.2 中生成底部图像.我想解决顶部图中标签的移位"以匹配底部的标签.此查询中给出的示例代码用于生成两个图.

Notice the diff in color scale label on two images. top image is the output from R 3.2.5, same code produces bottom image in R 2.15.2. I want to resolve the 'shift' of labels in the top plot to match the bottom one. Sample code given in this query was used to generate both plots.

我正在尝试使用 image.plot 绘制地图,但色阶的最小值和最大值并未准确显示在提示处.我在 R 版本 3.2.5 (2016-04-14) 中遇到了这个问题;平台:x86_64-w64-mingw32/x64(64 位)和库包字段"垃圾邮件版本 1.4-0 (2016-08-29)

I am trying to plot a map using image.plot but the min and max value of colorscale are not displayed exactly at the tips. I am facing this issue in R version 3.2.5 (2016-04-14); Platform: x86_64-w64-mingw32/x64 (64-bit) and library package 'fields' Spam version 1.4-0 (2016-08-29)

相比之下,在 R 版本 2.15.2 (2012-10-26),平台:x86_64-w64-mingw32/x64 (64-位)和字段"包 0.41-0 (2014-02-26).这是示例代码:

In contrast, the same commands could be correctly displayed the min and max values at the edges of color scale in R version 2.15.2 (2012-10-26), Platform: x86_64-w64-mingw32/x64 (64-bit) and 'fields' package 0.41-0 (2014-02-26). Here is sample code:

library(fields)
temp <- matrix(data=rexp(200, rate=10), nrow=180, ncol=360)
min(temp)
max(temp)
color_plate <- c("#FF0000", "#FF4D00", "#FF7000", "#FF8A00", "#FFA800", "#FFBF00", "#FFF000", "#FFFF54", "#AAFFFF","#7FFFFF", "#55FFFF", "#2AFFFF", "#00CFFF", "#20BFFF", "#209FFF", "#2060FF")

zlim <- seq(0.08,0.40,by=0.04)
temp[temp<min(zlim)] <- min(zlim)
temp[temp>max(zlim)] <- max(zlim)

image.plot(temp,col=color_plate, 
           axis.args=list(cex.axis =1,at=zlim, labels=zlim,mgp=c(1, 0, 0),tck=0.1))

推荐答案

我从 fields 包的包创建者那里得到了答案.将示例代码粘贴到此处供其他人使用..

I got the answer from package creator of fields package. Pasting the sample code here for others..

library(fields)

temp <- matrix( seq( 0,.5,,80), 8,10)

colTab <- c("#FF0000", "#FF4D00","#FF7000", "#FF8A00", "#FF7000")

N<- length( colTab)

breaks <- seq(0.08, 0.40,  length.out= N+1 )

image.plot(temp, col=colTab, breaks=breaks,
           axis.args=list(cex.axis =1, at=breaks, labels= breaks, mgp=c(1, 0, 0), tck=0.1)
     )

这篇关于R 中的 image.plot 不显示色标边缘的色标值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆