Plot Maps
The function takes a list
polygons and draws the corresponding map. Different
colors for each polygon can be used. Typically used for objects of class "mrf.bayesx"
and
"random.bayesx"
returned from function bayesx
and
read.bayesx.output
.
plotmap(map, x = NULL, id = NULL, c.select = NULL, legend = TRUE, missing = TRUE, swap = FALSE, range = NULL, names = FALSE, values = FALSE, col = NULL, ncol = 100, breaks = NULL, cex.legend = 1, cex.names = 1, cex.values = cex.names, digits = 2L, mar.min = 2, add = FALSE, interp = FALSE, grid = 200, land.only = FALSE, extrap = FALSE, outside = FALSE, type = "akima", linear = FALSE, k = 40, p.pch = 15, p.cex = 1, shift = NULL, trans = NULL, ...)
map |
the map to be plotted, the map object must be a |
x |
a matrix or data frame with two columns, first column indicates the region and
second column the the values which will define the background colors of the polygons, e.g.
fitted values from |
id |
if argument |
c.select |
select the column of the data in |
legend |
if set to |
missing |
should polygons be plotted for which no data is available in |
swap |
if set to |
range |
specify the range of values in |
names |
if set to |
values |
if set to |
col |
the color of the surface, may also be a function, e.g.
|
ncol |
the number of different colors that should be generated if |
breaks |
a set of breakpoints for the colors: must give one more breakpoint than
|
cex.legend |
text size of the numbers in the legend. |
cex.names |
text size of the names if |
cex.values |
text size of the names if |
digits |
specifies the legend decimal places. |
mar.min |
Controls the definition of boundaries. Could be either |
add |
if set to |
interp |
logical. Should the values provided in argument |
grid |
integer. Defines the number of grid cells to be used for interpolation. |
land.only |
if set to |
extrap |
logical. Should interpolations be computed outside the observation area (i.e., extrapolated)? |
outside |
logical. Should interpolated values outside the boundaries of the map be plotted. |
type |
character. Which type of interpolation metjod should be used. The default is
|
linear |
logical. Should linear interpolation be used withing function
|
k |
integer. The number of basis functions to be used to compute the interpolated surface
when |
p.pch |
numeric. The point size of the grid cells when using interpolation. |
p.cex |
numeric. The size of the grid cell points whein using interpolation. |
shift |
numeric. Constant to be added to the smooth before plotting. |
trans |
function to be applied to the smooth before plotting, e.g., to transform the plot to the response scale. |
... |
parameters to be passed to |
Function plotmap
uses per default the akima package to construct smooth interpolated
surfaces, therefore, package akima needs to be installed. The akima package has an ACM
license that restricts applications to non-commercial usage, see
Function plotmap
prints a note refering to the ACM licence. This note can be supressed by
setting
options("use.akima" = TRUE)
Nikolaus Umlauf, Thomas Kneib, Stefan Lang, Achim Zeileis.
## load a sample map data("FantasyBnd") ## plot the map op <- par(no.readonly = TRUE) plotmap(FantasyBnd, main = "Example of a plain map") plotmap(FantasyBnd, lwd = 1, main = "Example of a plain map") plotmap(FantasyBnd, lwd = 1, lty = 2) plotmap(FantasyBnd, lwd = 1, lty = 2, border = "green3") plotmap(FantasyBnd, lwd = 1, lty = 2, border = "green3", density = 50) plotmap(FantasyBnd, lwd = 1, lty = 2, border = c("red", "green3"), density = c(10, 20), angle = c(5, 45)) plotmap(FantasyBnd, lwd = 1, lty = 2, border = c("red", "green3"), density = c(10, 20), angle = c(5, 45), col = c("blue", "yellow")) plotmap(FantasyBnd, col = gray.colors(length(FantasyBnd))) ## add some values to the corresponding polygon areas ## note that the first column in matrix val contains ## the region identification index x <- cbind(as.integer(names(FantasyBnd)), runif(length(FantasyBnd), -2, 2)) plotmap(FantasyBnd, x = x) ## now only plot values for some certain regions set.seed(432) samps <- sample(x[,1], 4) nx <- x[samps,] plotmap(FantasyBnd, x = nx, density = 20) ## play with legend plotmap(FantasyBnd, x = x, names = TRUE, legend = FALSE) plotmap(FantasyBnd, x = nx, density = 20, pos = c(0, 1)) plotmap(FantasyBnd, x = nx, density = 20, pos = c(0, 0.8), side.legend = 2) plotmap(FantasyBnd, x = nx, density = 20, pos = c(0, 0.8), side.legend = 2, side.tick = 2) plotmap(FantasyBnd, x = nx, density = 20, pos = c(0, 0.8), side.legend = 2, side.tick = 2, cex.legend = 0.5) plotmap(FantasyBnd, x = x, values = TRUE, pos = c(-0.15, -0.12)) plotmap(FantasyBnd, x = nx, values = TRUE, pos = c(-0.07, -0.22), width = 2, at = nx[,2], side.legend = 2, distance.labels = 3, density = 20) plotmap(FantasyBnd, x = nx, values = TRUE, pos = c(-0.07, -0.22), width = 2, at = nx[,2], side.legend = 2, distance.labels = 3, density = 20, symmetric = FALSE, col = heat_hcl, swap = TRUE) plotmap(FantasyBnd, x = nx, values = TRUE, pos = c(-0.07, -0.22), width = 2, at = nx[,2], side.legend = 2, distance.labels = 3, density = 20, symmetric = FALSE, col = heat_hcl, swap = TRUE, range = c(-5, 5)) plotmap(FantasyBnd, x = nx, values = TRUE, pos = c(-0.07, -0.22), width = 2, at = nx[,2], side.legend = 2, distance.labels = 3, density = 20, symmetric = FALSE, col = heat_hcl, swap = TRUE, lrange = c(-5, 5)) plotmap(FantasyBnd, x = nx, values = TRUE, pos = c(-0.07, -0.22), width = 2, at = nx[,2], side.legend = 2, distance.labels = 3, density = 20, symmetric = FALSE, col = heat_hcl, swap = TRUE, ncol = 4, breaks = seq(-2, 2, length = 5)) ## more position options plotmap(FantasyBnd, x = nx, density = 20, pos = "bottomleft") plotmap(FantasyBnd, x = nx, density = 20, pos = "topleft") plotmap(FantasyBnd, x = nx, density = 20, pos = "topright") plotmap(FantasyBnd, x = nx, density = 20, pos = "bottomright") plotmap(FantasyBnd, x = nx, density = 20, pos = "right") par(op) # load and plot a map from GermanyBnd op <- par(no.readonly = TRUE) data("GermanyBnd") plotmap(GermanyBnd, main = "Map of GermanyBnd") n <- length(GermanyBnd) # add some colors plotmap(GermanyBnd, col = rainbow(n)) plotmap(GermanyBnd, col = heat.colors(n)) plotmap(GermanyBnd, col = topo.colors(n)) plotmap(GermanyBnd, col = cm.colors(n)) plotmap(GermanyBnd, col = gray.colors(n)) plotmap(GermanyBnd, col = c("green", "green3")) par(op) ## now with bayesx set.seed(333) ## simulate some geographical data data("MunichBnd") N <- length(MunichBnd); names(MunichBnd) <- 1:N n <- N*5 ## regressors dat <- data.frame(id = rep(1:N, n/N)) dat$sp <- with(dat, sort(runif(N, -2, 2), decreasing = TRUE)[id]) ## response dat$y <- with(dat, 1.5 + sp + rnorm(n, sd = 0.6)) ## Not run: ## estimate model b <- bayesx(y ~ sx(id, bs = "mrf", map = MunichBnd), method = "MCMC", data = dat) ## summary statistics summary(b) ## plot spatial effect op <- par(no.readonly = TRUE) plot(b, map = MunichBnd) plot(b, map = MunichBnd, c.select = "97.5 plot(b, map = MunichBnd, c.select = "2.5 plot(b, map = MunichBnd, c.select = "50 plot(b, map = MunichBnd, names = TRUE, cex.names = 0.5, cex.legend = 0.8) plot(b, map = MunichBnd, range = c(-0.5, 0.5)) plot(b, map = MunichBnd, range = c(-5, 5)) plot(b, map = MunichBnd, col = heat_hcl, swap = TRUE, symmetric = FALSE) par(op) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.