【发布时间】:2015-04-21 11:09:26
【问题描述】:
我有一个具有大量属性的raster 对象,我想在 R 中绘制空间数据并按某个属性对其进行颜色编码。我无法弄清楚如何使用特定属性的信息来实现这一点。到目前为止,我已经使用factorValues() 成功提取了选择属性,但我无法确定现在如何将此信息合并到plot() 函数中。我尝试使用光栅包文档中提到的ratify() 和level() 函数,但我不明白简化的在线示例如何适用于具有多个属性的光栅。
任何关于如何实现这一点的建议将不胜感激。
# read in shapefile
shp = readOGR(".", "grid")
#convert to raster
r = raster(extent(shp))
res(r) = c(1,0.5)
ra = rasterize(shp, r)
#crop raster to desired extent
rcrop = crop(ra, extent(-12, 2, 29, 51))
# extract attribute value of interest
f = factorValues(rcrop, 1:420, layer=1, att=17, append.names=FALSE)
# here there are 420 cells in the raster and I am interested in plotting values of attribute 17 of the raster (this is currently a numeric attribute, not a factor)
#extra code to set attribute as the level to use for plotting colours???
rcrop = ratify(rcrop)
rat = levels(rcrop)[[1]] #this just extras row IDs..not what I want
#…
### plot: I want to plot the grid using 7 colours (I would ideally like to specify the breaks myself)
require(RColorBrewer)
cols = brewer.pal(7,"YlGnBu")
#set breaks
brks = seq(min(minValue(rcrop)),max(maxValue(rcrop),7))
#plot
plot(rcrop, breaks=brks, col=cols, axis.arg=arg)
【问题讨论】:
标签: r plot attributes raster