Learn R Programming

d3po (version 1.0.3)

po_treemap: Treemap

Description

Plot a treemap

Usage

po_treemap(d3po, ..., data = NULL, inherit_daes = TRUE)

Value

an 'htmlwidgets' object with the desired interactive plot

Arguments

d3po

Either the output of d3po() or d3po_proxy().

...

Aesthetics, see daes().

data

Any dataset to use for plot, overrides data passed to d3po().

inherit_daes

Whether to inherit aesthetics previous specified.

Examples

Run this code
if (interactive()) {
  trade_by_continent <- d3po::trade[d3po::trade$year == 2023L, ]
  trade_by_continent <- aggregate(trade ~ reporter_continent, data = trade_by_continent, FUN = sum)

  # my_pal <- tintin::tintin_pal(option = "The Secret of the Unicorn")(7)
  # [1] "#0A9F5F" "#0C8FA0" "#3487B6" "#46AE5E" "#66A2A3" "#A7B7A9" "#BEB670"

  my_pal <- c("#0A9F5F", "#0C8FA0", "#3487B6", "#46AE5E", "#66A2A3", "#A7B7A9", "#BEB670")

  names(my_pal) <- c(
    "Africa", "Antarctica", "Asia",
    "Europe", "North America", "Oceania", "South America"
  )

  d3po(trade_by_continent, width = 800, height = 600) %>%
    po_treemap(daes(
      size = trade, group = reporter_continent,
      color = my_pal, tiling = "Squarify"
    )) %>%
    po_labels(title = "Trade Share by Continent in 2023")
}

Run the code above in your browser using DataLab