简体   繁体   English

将图例放置在栅格图下方,并摆脱栅格图周围的矩形

[英]placing legend below a raster plot and getting rid of the rectangle surrounding raster plot

I am plotting a raster image from the data stored in a file by using the three lines of code given below. 我正在使用下面给出的三行代码从文件中存储的数据绘制光栅图像。 However, I wish to generate a legend (or color-chart) below the image. 但是,我希望在图像下方生成图例(或颜色图表)。 The default legend is generated on the right hand side. 默认图例在右侧生成。 Any idea how I may get legend at desired location. 知道我如何在所需位置获得图例。 Secondly, I am getting a rectangle around the image which I don't require in the final plot. 其次,我得到的图像周围是一个矩形,这在最终绘图中不需要。 Please help me with these issues. 请帮助我解决这些问题。

            temp_var<-raster(input)
    par(mar=c(0,0,0,0))
    plot(temp_var,legend=F,axes=FALSE)

Thanks... 谢谢...

I have fought with the rectangle in plot() method for Raster* objects. 我已经为Raster*对象在plot()方法中使用了矩形。 I am sure there is a way to get rid of it, but you don't need to. 我敢肯定有一种方法可以摆脱它,但是您不必这样做。 I have always used this workaround: 我一直使用这种解决方法:

image(temp_var, axes=FALSE, xlab="", ylab="")

As for your legend, I believe you will have to build that manually to your specs. 至于您的传说,我相信您将必须根据您的规格手动进行构建。 Try: 尝试:

layout(matrix(c(1,1,1,1,1,2,2), 7, 1))
par(mar=c(0,0,0,0))
image(temp_var, axes=FALSE, xlab="", ylab="")
plot(c(0,1), c(0,1), type="n", xlab="", ylab="", axes=FALSE)
legend(0.1,0.9, legend=c(1:5), fill=rainbow(5), horiz=TRUE)

I've used colorbar.plot with some success in the past. 我过去曾经使用colorbar.plot取得了一些成功。 Disable the legend that plot(raster(x)) automatically inserts with legend=FALSE and then call colorbar.plot(), ie 禁用图例(raster(x))自动以图例= FALSE插入的图例,然后调用colorbar.plot(),即

plot(raster(x),legend=FALSE)
colobar.plot(...) 

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

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