【问题标题】:How to set the default theme for spplot?如何为 spplot 设置默认主题?
【发布时间】:2016-04-15 14:28:53
【问题描述】:

假设我有一些空间数据,我想使用 sp 包中的spplot 函数对其进行绘制:

library('sp')
library('lattice')
demo(meuse, ask = FALSE, echo = FALSE)
spplot(meuse.grid[,'dist'])

只需一个情节即可轻松更改主题,例如 col.regions:

spplot(meuse.grid[,'dist'], col.regions=rainbow(100))

但是,如果我想更改所有绘图的 col.regions 怎么办?我尝试了一些功能,例如:

trellis.par.set(sp.theme(set = FALSE, regions = list(col = rainbow(100)))) #1
trellis.par.set(regions = list(col = rainbow(100))) #2
lattice.options(default.theme = sp.theme(set = FALSE, regions = list(col = rainbow(100)))) #3

但似乎没有任何效果。所以我的问题是 - 如何正确设置 spplot 的默认主题?

【问题讨论】:

    标签: r plot gis lattice sp


    【解决方案1】:

    查看以下代码以手动重新定义spplot 的默认配色方案(另请参阅?spplot,其中进一步描述了set_col_regions)。

    ## re-define default color scheme
    old_theme <- get_col_regions()
    new_theme <- set_col_regions(rainbow(100))
    
    ## sample data
    data("meuse.grid")
    coordinates(meuse.grid) <- ~x+y
    proj4string(meuse.grid) <- CRS("+init=epsg:28992")
    gridded(meuse.grid) <- TRUE
    
    ## display data with c
    spplot(meuse.grid, zcol = "dist")                
    

    自定义配色方案适用于任何随后创建的“spplot”对象,例如

    library(mapview)
    spplot(poppendorf, "B007n")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-15
      • 2016-12-12
      • 1970-01-01
      • 1970-01-01
      • 2016-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多