sp_plot: Plot methods for spatial data with attributes

View source: R/sp_plot.R

sp_plotR Documentation

Plot methods for spatial data with attributes

Description

Lattice (trellis) plot methods for spatial data with attributes

Usage

sp_plot(
  grid,
  df = grid@data,
  zcols,
  formula = NULL,
  df.mask = NULL,
  brks,
  cols,
  strip = FALSE,
  strip.factors = NULL,
  toFactor = FALSE,
  panel.titles_full = NULL,
  panel = panel.spatial,
  xlim = NULL,
  ylim = NULL,
  unit = "",
  unit.adj = 0.3,
  area.weighted = FALSE,
  colorkey = TRUE,
  key.space = "right",
  key.height = 0.98,
  key.num2factor = FALSE,
  interpolate = FALSE,
  lgd.title = NULL,
  sp.layout = NULL,
  layout = NULL,
  NO_begin = 1,
  cex.lgd = 1.3,
  par.strip.text = NULL,
  par.settings = opt_trellis_default,
  par.settings2 = list(axis.line = list(col = "transparent")),
  ...
)

Arguments

df

data.table object, with columns e.g. lon, lat, and others

formula

a formula of the form z ~ s1 + s2 | g1 * g2 * ..., where z is a numeric response, and x, y are numeric values evaluated on a rectangular grid. g1, g2, ... are optional conditional variables, and must be either factors or shingles if present.

df.mask

NULL or same length data.table as df, with the columns of mask and same group variabes as df. mask is a boolean vector, which is used to distinguish significant pixels. Note that factor levels should be same for grouped variables in df and df.mask.

brks

either a numeric vector of two or more unique cut points to convert values in df into factor.

cols

corresponding colors of every break interval

panel.titles_full

string or expression vectors of panel titles, default NULL. If provided, group names in df will be overwritten.

panel

panel function used to create the display, as described in xyplot

xlim, ylim

The limits of x and y

colorkey

Boolean or list returned by get_colorkey(). list object can be passed to draw.colorkey() directly.

sp.layout

NULL or list; see notes below

NO_begin

beginning NO of the first panel

...

Further arguments may be supplied. Some are processed by levelplot or contourplot, and those that are unrecognized are passed on to the panel function.

pars

parameters controlling the position of histogram and panel titles, e.g. list(title = list(x=77, y=39, cex=1.5), hist = list(origin.x=77, origin.y=28)).

SpatialPixel

corresponding SpatialPixel object of df

If mask present in df, df.mask will be ignored.

Note

parameter panel.title change to panel.titles_full

  • panel.titles_full is for tags.

  • strip.factors is for strip factors

See Also

sp::spplot(), lattice::levelplot()

Examples

library(Ipaper)
library(lattice)

set_font()
data("grid_avhrr")
pars = list(title = list(x=77, y=39, cex=1.2))

trellis.par.set("add.text" = list(fontfamily = get_family(), cex = 2))
p <- sp_plot(grid_avhrr,
             pars = pars,
             interpolate = FALSE) +
    layer_barchart(x = 0.05, y = 0.15, width = 0.25) +
    layer_latFreq(zlim_ratio = c(0, 1), bbox = c(0.8, 1, 0, 1)) +
    layer_statistic(x = 0.5, y = 0.6, FUN = weightedMedian) +
    layer_signPerc(x = 0.05, y = 0.6) +
    layer_signDist()
write_fig(p, show = FALSE)
# write_fig(p, "ex-sp_plot1.pdf", 9.8, 5)

## levelplot stype
df = grid_avhrr@data %>% data.frame() %>%
    list(a = ., b = .) %>% melt_list("type")
sp_plot(grid_avhrr, df,
              formula = X1982 ~ lon+lat | type,
              aspect = 0.5, pars = pars) +
    layer_barchart(x = 0.05, y = 0.15, width = 0.25) +
    layer_latFreq(zlim_ratio = c(0, 1), bbox = c(0.9, 1, 0, 1)) +
    layer_statistic(x = 0.5, y = 0.6, FUN = weightedMedian) +
    layer_signPerc(x = 0.05, y = 0.6) +
    layer_signDist()
# write_fig(p2 , "ex-sp_plot2.pdf", 6, 5)
## show strip
sp_plot(grid_avhrr, df, zcols = 2,
              # formula = X1982 ~ lon+lat | type,
              strip = TRUE,
              par.settings2 = list(axis.line = list(col = "black")),
              aspect = 0.5, pars = pars)
# write_fig(p3 , "ex-sp_plot3.pdf", 6, 5)

kongdd/latticeGrob documentation built on March 30, 2024, 3:35 a.m.