build_pmap: Build a pixel map

View source: R/build_pmap.R

build_pmapR Documentation

Build a pixel map

Description

This function builds a choropleth map that visualises estimates and errors simultaneously through pixelation and sampling.

Usage

build_pmap(
  data = NULL,
  distribution = NULL,
  pixelGeo,
  id,
  border = NULL,
  palette = "Blues",
  q = NULL,
  limits = NULL
)

Arguments

data

A data frame.

distribution

Name of the distribution that the pixel assignments will be drawn from. It must be one of discrete, normal or uniform. If distribution = "discrete", a data frame of the quantiles that define the relative frequency distribution for the estimate must be entered for q. If distribution = "normal", the values assigned to pixels will be drawn from a normal distribution parameterised using the estimates and errors (means and standard deviations). If distribution = "uniform", values will be sampled with equal probability from a sequence of 5 numbers that spans the estimate minus its error to the estimate plus its error.

pixelGeo

An object from pixelate.

id

Name of the common column shared by the objects passed to data, pixelGeo and q (if distribution = "discrete").

border

An sf or sp object. Or, one of county, france, italy, nz, state, usa or world; these borders will be refined to match latitude and longitude coordinates provided in the geoData argument.

palette

Name of colour palette. It must be one of Blues, Greens, Greys, Oranges, Purples or Reds (see documentation for scale_fill_distiller for more information).

q

A data frame of quantiles which define the distribution for each estimate. Each row is an estimate, and each column is a quantile. See examples for an example of q input.

limits

Limits for the legend. Default is NULL, which takes the limits to be the range of the data.

See Also

animate

Examples

## Not run: 
# This code will produce a pixelated map when run in R
# It is not run here.
data(us_geo)
ca_geo <- subset(us_geo, us_geo@data$STATE == "06")
pix <- pixelate(geoData = ca_geo, pixelSize = 70, id = "GEO_ID")

data(us_data)
us_data$GEO.id2 <- as.numeric(us_data$GEO.id2)
ca_data <- subset(us_data, us_data$GEO.id2 > 6000 & us_data$GEO.id2 < 7000)
ca_data <- read.uv(data = ca_data, estimate = "pov_rate", error = "pov_moe")
row.names(ca_data) <- seq(1, nrow(ca_data), 1)

# uniform distribution
m <- build_pmap(data = ca_data, distribution = "uniform", pixelGeo = pix, id = "GEO_ID")
view(m)

# normal distribution
ca_data$se <- ca_data$pov_moe / 1.645
ca_data <- read.uv(data = ca_data, estimate = "pov_rate", error = "se")

m <- build_pmap(data = ca_data, distribution = "normal", pixelGeo = pix, id = "GEO_ID")
view(m)

# experiment with discrete distribution
# exponential - example for q argument
ca_data.q <- with(ca_data, data.frame(p0.05 = qexp(0.05, 1/pov_rate),
 p0.25 = qexp(0.25, 1/pov_rate), p0.5 = qexp(0.5, 1/pov_rate),
 p0.75 = qexp(0.75, 1/pov_rate), p0.95 = qexp(0.95, 1/pov_rate)))

m <- build_pmap(data = ca_data, distribution = "discrete", pixelGeo = pix,
 id = "GEO_ID", q = ca_data.q)
view(m)

## End(Not run)

pkuhnert/VizU documentation built on Nov. 2, 2024, 4:52 p.m.