Skip to contents

Import

library(bertin)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
world <- st_read(system.file("gpkg/world.gpkg", package = "bertin"),
                 layer = "world", quiet = TRUE)

Bubble

bt_param(margin = 10, width = 800)|>
  bt_graticule(strokeWidth = 1.5, strokeDasharray = 2, stroke  = "green", 
               step  = 5)|>
  bt_layer(data = world, fill = "#808080") |>
  bt_bubble(data = world, values = "pop", k = 30, tooltip = "$pop") |>
  bt_header(text = "What a Map!", fontSize = 40) |>
  bt_footer(text="Credit lines, super long super long super long super ", 
            fontSize = 8) |>
  bt_draw()

Typo

Adapted from https://observablehq.com/@neocartocnrs/bertin-js-typo?collection=@neocartocnrs/bertin

bt_param(projection = "InterruptedHomolosine", clip = TRUE) |>
  bt_outline() |>
  bt_graticule() |>
  bt_shadow(data = world, opacity = 0.2) |>
  bt_layer(data = world,
           tooltip = c("$region", "$name", " "),
           fill = list(
             type = "typo",
             values = "region",
             strokeWidth = 0.3,
             colors = "Tableau10",
             leg_title = "The Continents",
             leg_x = 55,
             leg_y = 180
           )) |>
  bt_draw()

Choropleth

Adapted from https://observablehq.com/@neocartocnrs/bertin-js-chropoleth?collection=@neocartocnrs/bertin

bt_param(projection = "Eckert3", clip = TRUE) |>
  bt_outline() |>
  bt_graticule() |>
  bt_layer(data = world,
           fill = list(
             type = "choro",
             values = "gdppc",
             nbreaks = 7,
             method = "quantile",
             colors = "RdYlGn",
             leg_round = -2,
             leg_title = "GDP per inh\n(in $)",
             leg_x = 100,
             leg_y = 200
           ), tooltip = c("$name", "$gdppc", "(current US$)")) |>
  bt_draw()

Stock + Typo

Adapted from https://observablehq.com/@neocartocnrs/bertin-js-stock-typo?collection=@neocartocnrs/bertin

bt_param(projection = "InterruptedMollweideHemispheres", clip = TRUE) |>
  bt_outline(fill = "#ADD8F7") |>
  bt_layer(data = world, fill = "white", fillOpacity = .35) |>
  bt_graticule() |>
  bt_bubble(data = world,
            values = "pop", k = 60, fill = list(
              type = "typo",
              values = "region",
              leg_x = 100,
              leg_y = 100,
              leg_title = "The Continents"
            ), tooltip = list(
              fields = c("$name", " ", "Continent", "$region", "Population", "$pop"),
              fontSize = c(25, 10, 14, 12, 14, 12),
              fontWeight = c("bold", "normal", "bold", "normal", "bold", "normal")
            ),
            leg_round = -2,
            leg_x = 100,
            leg_y = 300,
            leg_title = "Population") |>
  bt_draw()

Stock + Choro

Adapted from https://observablehq.com/@neocartocnrs/bertin-js-stock-choro?collection=@neocartocnrs/bertin

bt_param(projection = "PolyhedralWaterman") |>
  bt_outline() |>
  bt_layer(data = world, fill = "white", fillOpacity = .3) |>
  bt_graticule() |>
  bt_bubble(data = world, leg_round = -2, k = 55, values = "pop",
            fill = list(
              type = "choro", method = "quantile", nbreaks = 7, 
              values = "gdppc", colors = "RdYlGn", 
              leg_title = "GDP per capital\n(in $)",
              leg_x = 100, leg_y =270, leg_round = -2
            ),
            tooltip = c("$name", "$gdppc", "(current US$)"),
            leg_title = "Number of inh.",
            leg_x = 800, leg_y = 270
  ) |>
  bt_draw()

Regular Bubble

Adapted from https://observablehq.com/@neocartocnrs/bertin-js-regular-bubbles?collection=@neocartocnrs/bertin

bt_param(projection = "Bertin1953", width = 600) |>
  bt_outline() |>
  bt_layer(data = world, fill = "white", fillOpacity = .3) |>
  bt_graticule() |>
  bt_header(text = "World Population (step = 10)") |>
  bt_regularbubble(data = world, step = 10, values = "pop", k = 10) |>
  bt_draw()

Tissot’s indicatrix

bt_param(projection = "Eckert3", clip = TRUE) |>
  bt_outline() |>
  bt_layer(data = world, fill = "white", fillOpacity = .3) |>
  bt_tissot(step = 20) |>
  bt_draw()