knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
We start with the standard map fhidata::norway_map_counties_b2020
and provide data:
# start off with base map pd <- fhimaps::norway_nuts3_map_b2020_insert_oslo_dt # create some fictional data data <- unique(pd[,c("location_code")]) suppressWarnings(data[,category:=rep(c("High","Medium","Low"),each=5)[1:.N]]) data[,category_with_missing:=category] data[1,category_with_missing:="Missing"] data[,category:=factor(category,levels=c("High","Medium","Low"))] data[,category_with_missing:=factor(category_with_missing,levels=c("High","Medium","Low","Missing"))] data[location_code == "county54", category:='Low'] data[location_code == "county54", category_with_missing:='Low'] # merge the data into the map pd[data,on="location_code",category:=category] pd[data,on="location_code",category_with_missing:=category_with_missing]
If your data does not contain any missing, then we recommend to use the _complete
map palettes:
library(ggplot2) library(fhiplot) q <- ggplot() q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group, fill=category), color="black") q <- q + theme_void() q <- q + coord_quickmap() q <- q + fhiplot::scale_fill_fhi("Category",palette = "map_seq_complete", direction = 1, drop=F) q <- q + labs(title = "Palette = map_seq_complete") q
library(ggplot2) library(fhiplot) q <- ggplot() q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group, fill=category), color="black") q <- q + theme_void() q <- q + coord_quickmap() q <- q + fhiplot::scale_fill_fhi("Category",palette = "map_seq_x2_complete", direction = 1, drop=F) q <- q + labs(title = "Palette = map_seq_x2_complete") q
If your data does contain missing, then we recommend to use the _missing
map palettes:
library(ggplot2) library(fhiplot) q <- ggplot() q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group, fill=category_with_missing), color="black", size=0.2) q <- q + theme_void() q <- q + coord_quickmap() q <- q + fhiplot::scale_fill_fhi("Category",palette = "map_seq_missing", direction = 1, drop=F) q <- q + labs(title = "Palette = map_seq_missing") q
library(ggplot2) library(fhiplot) q <- ggplot() q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group, fill=category_with_missing), color="black", size=0.2) q <- q + theme_void() q <- q + coord_quickmap() q <- q + fhiplot::scale_fill_fhi("Category",palette = "map_seq_missing_x2", direction = 1, drop=F) q <- q + labs(title = "Palette = map_seq_missing_x2") q
library(ggplot2) library(fhiplot) q <- ggplot() q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group, fill=category_with_missing), color="black", size=0.2) q <- q + theme_void() q <- q + coord_quickmap() q <- q + fhiplot::scale_fill_fhi("Category",palette = "map_seq_x2_missing", direction = 1, drop=F) q <- q + labs(title = "Palette = map_seq_x2_missing") q
library(ggplot2) library(fhiplot) q <- ggplot() q <- q + geom_polygon(data = pd, aes( x = long, y = lat, group = group, fill=category_with_missing), color="black", size=0.2) q <- q + theme_void() q <- q + coord_quickmap() q <- q + fhiplot::scale_fill_fhi("Category",palette = "map_seq_x2_missing_x2", direction = 1, drop=F) q <- q + labs(title = "Palette = map_seq_x2_missing_x2") q
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.