can.plot: Plotting canton-level maps of Switzerland

Description Usage Arguments Examples

Description

can.plot offers the possbility to visualise Swiss canton-level data on a map. It uses the geodata that is made publicly available by the Swiss Federal Statistical Office. Geodata is available for the period between 2001 to 2017. The argument cantons makes it easy to plot customised maps. The function can.template provides templates for data collection.

Usage

1
2
3
4
5
6
7
8
can.plot(bfs_id, data, year, add_geodata_path = ".", endofyear = FALSE,
  cantons = NULL, lakes = "all", boundaries = "c",
  boundaries_size = 0.2, boundaries_color = "white", extrema = "global",
  continuous = TRUE, color_continuous = c("#fee5d9", "#a50f15"),
  color_discrete = c("seq", "1"), color_na = "gray90", title = NULL,
  subtitle = NULL, caption = NULL, legend_title = NULL,
  legend_position = "bottom", save = FALSE, filename = "can_plot.png",
  dpi = 300, width = NA, heigth = NA, units = "cm")

Arguments

bfs_id

a numeric vector with canton identification numbers as used by the Swiss Federal Statistical Office corresponding to data. For templates, see can.template.

data

a vector of data at canton-level.

year

numeric. Indicates what map version to plot. Available with package: 2016. For additional geodata, see: map.load.

add_geodata_path

a character string with the path to the folder where additional geodata is saved.

endofyear

if TRUE, administrative boundaries as by December 31 of year are plotted. Available: year > 2010.

cantons

input either numeric (canton identification numbers) or character (canton abbreviations) vector to plot district of selected cantons.

lakes

input either numeric (lake identification numbers) or character (lakes names) vector to plot selected lakes. If "none", no lakes are plotted. If "all", all available lakes are plotted.

boundaries

character vector naming the boundaries to map.

  • "c": canton boundaries

  • "n": national boundaries

boundaries_size

numeric vector that specifies the size of the corresponding element in boundaries.

boundaries_color

character vector that specifies the color of the corresponding element in boundaries.

extrema

if local, data of municipalities that are not selected by cantons is not considered in the color scaling process.

continuous

set to FALSE, if data is non-continuous.

color_continuous

character vector with 2 elements to specifiy the plot color if continuous = TRUE. color_continuous = c(low, high) resulting in a two color gradient from color low to color high.

color_discrete

character vector with 2 elements to specifiy the plot color if continuous = FALSE. color_discrete = c(type, palette) resulting in a color scheme from ColorBrewer that are particularly well suited to display discrete values on a map.

  • type: one of seq (sequential), div (diverging) or qual (qualitative)

  • palette: index into the list of palettes of appropriate type; character needed!

color_na

color of missing values.

title, subtitle, caption, legend_title

text for titles or caption below the plot.

legend_position

the position of the legend ("none", "left", "right", "bottom", "top")

save

if TRUE, the plot will be saved to disk.

filename

file name to create on disk incl. image file format (".jpeg", ".png", ".tiff", etc.).

dpi

plot resolution. Applies only to raster output types.

width, heigth, units

plot size in units ("in", "cm", or "mm"). If not supplied, uses the size of current graphics device.

Examples

1
2
3
4
5
6
 # Generating sample data:
 dt <- can.template(2016)
 for(i in 1:nrow(dt)){dt$values[i] <- sample(c(300:700), 1)/1000}

 # Plotting sample data:
 can.plot(dt$bfs_nr, dt$values, 2016)

Example output

Warning messages:
1: Use of `data_combined_1$data` is discouraged. Use `data` instead. 
2: Use of `data_combined_ai_ar$data` is discouraged. Use `data` instead. 

RSwissMaps documentation built on June 10, 2019, 1:02 a.m.