knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(tuichartr) library(rnaturalearth)
You can make continuous maps with tuichartr
and tuimaps
function. It works with sf
objects, we'll use package rnaturalearth
to retrieves shapes.
Mapping for creating a map require 3 aesthetics:
# Retrieve Italy polygons italy <- ne_states("italy", returnclass = "sf") # add a random numeric variable italy$random <- sample(1:100, nrow(italy), TRUE) # draw map tuimap(width = 500, height = 500) %>% add_map_data(italy, aes(code = adm1_code, label = name, value = random)) %>% tui_chart(title = "Italy map")
An other example, with some options:
africa <- ne_countries(continent = "africa", returnclass = "sf") africa$random <- sample(1:100, nrow(africa), TRUE) tuimap(width = 700, height = 900) %>% add_map_data(africa, aes(code = sov_a3, label = name, value = random)) %>% tui_chart( title = "Africa map", format = JS("function(value) {return value + '%'}") ) %>% tui_theme( series = list( startColor = "#DEEBF7", endColor = "#084594" ) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.