简体   繁体   中英

How to set the default theme for spplot?

Let's say, I have some spatial data and I want to plot it using spplot function from sp package:

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

在此输入图像描述

It's easy to change the theme, for example col.regions, for only one plot:

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

在此输入图像描述

However, what if I want to change the col.regions for all of my plots? I've tried a few functions, for example:

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

But nothing seems to work. So my question is - how to properly set the default theme for spplot?

Have a look at the following code in order to manually re-define the default color scheme for spplot (see also ?spplot where set_col_regions is further described).

## 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

The customized color scheme persists for any subsequently created 'spplot' object, eg

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

MapView类

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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