2015-12-07 78 views
1

我需要繪製柵格文件。R - 繪製柵格時移動圖例的最簡單方法

在我的輸出圖像中,圖例上的數字有時不可見 - 特別是當我將圖形窗口分割成兩列或更多列時(例如:par(mfrow = c(1,2))))。

我想過將圖例移動到底部(下面的柵格圖像)來解決此問題。 但是,我發現的大多數示例都建議使用全新的顏色和項目定義創建全新的圖例。

我想使用默認的圖例。我只需要將它移到底部。我試圖做到這一點,如下所示:

library('raster') 
data(volcano) 
r <- raster(volcano) 
# Trying to draw default legend below raster plot 
plot(r, legend=F) 
# Now trying to draw legend. Default is okay for me, I want to move it below only: 
plot(r, legend.only=TRUE, legend.args=list("bottom", text='My values [m^3]')) 

不幸的是,我的代碼不工作(好像沒有使用「底」參數)。

What I need to achieve

+0

有喲你遇到任何方式來修改圖例文字的顏色? –

+0

不,我不需要改變圖例文字的顏色。 – matandked

回答

0

Here是使用rasterVis方式:spplot

library(rasterVis) 
levelplot(r, margin=FALSE, colorkey=list(space="bottom"), par.settings = RdBuTheme()) 

enter image description here

+0

'rasterVis'之外有沒有辦法修改圖例的文字顏色?我使用'smallplot'將我的圖例置於我的圖中 –

0

或者嘗試,它也使用包lattice

spplot(r, scales = list(draw = TRUE), colorkey = list(space = "bottom")) 
+0

這可行,但我也在我的光柵中添加了一些shapefile,例如:plot(punktyPom,add = T,lwd = c(1),lty = c 1))'和'spplot'似乎無法正常工作 – matandked