tm_dots
), where the dots are colored according to the classes.
sample_dots(shp, vars = NULL, convert2density = FALSE, nrow = NA, ncol = NA, N = 250000, npop = NA, n = 10000, w = NA, shp.id = NULL, var.name = "class", var.labels = vars, unit = "km", unit.size = 1000, randomize = TRUE, output = c("points", "grid"), ...)
SpatialPolygonsDataFrame
.shp
. If vars
is not provided, the dots are sampled uniformly. If vars
consists of one variable name, the dots are sampled according to the distribution of the corresponding variable. If vars
consist of more than one variable names, then the dots are sampled according to the distributions of those variables. A categorical variable is added that contains the distrubtion classes (see var.name
).TRUE
when the values are absolute counts.NA
, it is recontructed from the data. If density values are specified, the population total is approximated using the polygon areas (see also unit
and unit.size
).n
. If specified, n
is calculated accordingly.shp
that contains the polygon identifying numbers or names.vars
, and the labels can be configured with var.labels
.var.name
).calc_densities
. Needed to relate npop
to w
, if they are not both specified.calc_densities
. Needed to relate npop
to w
, if they are not both specified.vars
). If this order is not randomized (so if randomize=FALSE
), then the dots from the last class will be drawn on top, which may introduce a perception bias. By default randomize=TRUE
, so the sampled dots are randomized to prevent this bias."points"
for spatial points, and "grid"
for a spatial grid.calc_densities
and approx_areas
## Not run:
# data(World)
# World_dots <- sample_dots(World, vars="pop_est_dens", nrow=200, ncol=400, w=1e6)
#
# tm_shape(World_dots) + tm_dots(size = .02, jitter=.1) +
# tm_layout("One dot represents one million people", title.position = c("right", "bottom"))
# ## End(Not run)
Run the code above in your browser using DataLab