library(ggswissmaps) data("shp_df") class(shp_df) length(shp_df) names(shp_df)
# Data description ?shp_df
names(maps2) # By name maps2[["g1k15"]] # By index maps2[[5]]
The objects contained in maps2
are ggplot
objects. They have been created with ggplot2::ggplot
plus a ggplot2::geom_path
layer with the data in shp_df
. As an example, the previous map is the same as:
ggplot(shp_df[["g1k15"]], aes(x = long, y = lat, group = group)) + geom_path() + coord_equal() + theme_white_f()
The maps2
object, used above, is a list with some maps of swiss territory at various levels (grand regions, cantons, districts, ...).
What if one wants to draw a map with a sub-territory? For example, what if I want to have a map with the districts of two cantons? First, I have to select the desired subset from the shp_df
data, and then will apply the maps2_
function to it.
# Data frame with the coordinates of all swiss districts d <- shp_df[["g1b15"]] # Look at the structure of the data frame str(d) # The cantons are identified by the KTNR column # Extract from this data the districts of two cantons library(dplyr) d <- d %>% dplyr::filter(KTNR %in% c(18, 21)) # And draw the map maps2_(d)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.