简体   繁体   English

R spplot:颜色条而不是 SpatialPoint 数据的图例

[英]R spplot: colorbar rather than legend for SpatialPoint data

I am plotting a SpatialPoint dataframe in R using spplot, and I would like to use a colorbar rather than a legend, to portray color values.我正在使用 spplot 在 R 中绘制 SpatialPoint 数据框,并且我想使用颜色条而不是图例来描绘颜色值。 (It's more efficient, and I want the map to "match" previous, raster data maps.) I'm sure this is possible, but can find no examples of it online. (它更有效,我希望地图“匹配”以前的栅格数据地图。)我确信这是可能的,但在网上找不到它的例子。 Could anyone give me a hint?谁能给我一个提示?

My current code is:我目前的代码是:

my.palette <- brewer.pal(n = 9, name = "Spectral")
my.palette<- rev(my.palette)
pols1 <- list("sp.lines", as(ugborder, 'SpatialLines'), col = gray(0.4), lwd = 1)
pols2 <- list("sp.polygons", as(water_ug, 'SpatialPolygons'), fill = 'skyblue1',col="transparent", first = FALSE)

spplot(ughouseszn,zcol="lzn_sg_clng",cex = .75,
   key.space="right", digits=1,
   par.settings = list(axis.line = list(col =  'transparent')), 
   xlim = bbox(ugborder)[1, ],ylim = bbox(ugborder)[2, ],
   col.regions = my.palette, cuts=8,
   sp.layout=list(pols1, pols2))

Where ugborder and water_ug give Uganda's borders and water, ughouseszn is a SpatialPointsDataframe, and the resulting map is here:其中 ugborder 和 water_ug 给出了乌干达的边界和水域,ughouseszn 是一个 SpatialPointsDataframe,生成的地图在这里: 在此处输入图片说明

(As a side note, I'm hoping that adding a colorbar will lead to a more efficient use of space -- right now there's a lot of extra space at the top and bottom of Uganda's border, which is useless, and also does NOT appear when I map raster data using spplot, with the same pols1 and pols2.) (作为旁注,我希望添加颜色条可以更有效地利用空间——现在乌干达边界的顶部和底部有很多额外的空间,这是无用的,也没有当我使用 spplot 映射栅格数据时出现,具有相同的 pols1 和 pols2。)

If "lzn_sg_clng" is converted to a factor, does this give you the map you desire?如果将“lzn_sg_clng”转换为一个因子,这是否为您提供了您想要的地图? (rendering by the category rather than a graduated scale). (按类别而非分级比例呈现)。

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

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