繁体   English   中英

使用image.plot函数时,如何仅显示图例中的最小值和最大值

[英]how to display only the minimum and the maximum values in a legend while using image.plot function

我正在使用image.plot函数来显示带有图像的颜色条。 对于颜色条,我希望仅在其边界位置显示图例。 但是,目前我正在中间的各个地方进行抽动。 而且,没有显示相应的值。 请参阅下面的代码段:

  color_plate=c('royalblue4','springgreen4','yellow2','darkred')
    layout(matrix(c(1,1), 1, 1))
    par(mar=c(0,1,1,0))
#here image is plotted
    image(image_variable, axes=FALSE, xlab="", ylab="",col=color_plate)

   image.plot(zlim=c(min(ya),max(ya)),legend.only=TRUE,col=color_plate,
    horizontal=TRUE,legend.mar=0.4,legend.shrink=0.4,legend.width=0.4,
    axis.args = list(cex.axis = 1.5))

#here color bar is added but I am not able to generate legend values at both ends.    
#Furthermore, I wish to eliminate the tics and only need the values to be displayed.                          
# I also tried two variations within the image.plot function but no result:
#axis.args = list(cex.axis = 1.5,at=c(floor(min(ya)),ceiling(max(ya))))
#and  
#axis.args = list(cex.axis = 1.5, at=c(0.01,0.05),labels=c(0.01,0.05))

请在该细分中建议适当的修改。

提前致谢。 Munish

虽然我不能运行你的例子,我想我明白你的意思,我想你可以调整你的layout(..) 纵观?image.plot ,有你想要的东西一个例子-您使用breaks参数和lab.breaks参数image.plot

# generate an image_variable for demonstration
image_variable <- array(runif(100),dim=c(10,10))
color_plate=c('royalblue4','springgreen4','yellow2','darkred')

library(fields) # for image.plot
# This puts the colour scale marks within the colour bar, not on the boundaries:
# image.plot(image_variable,col=color_plate,zlim=c(0,1),...)

zlim <- c(0,1)
# define colour breaks (they were default spaced evenly):
brks = seq(0,1,length.out=length(color_plate)+1)

# plot:
image.plot(image_variable, zlim=zlim, axes=F,
           col=color_plate, breaks=brks, lab.breaks=brks)

在此输入图像描述

希望这就是你想要的。

如果你想要0和1,那就更容易了:

image.plot(image_variable, col=color_plate, zlim=zlim, axes=F,
       axis.args=list(at=zlim, labels=zlim))

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM