Learn R Programming

d3po (version 1.0.3)

po_donut: Donut

Description

Plot a donut

Usage

po_donut(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 = d3po::trade,
    FUN = sum
  )

  # Assign colors to continents
  # my_pal <- tintin::tintin_pal(option = "The Black Island")(7)
  # [1] "#2D5992" "#478CB3" "#6D92A0" "#727786" "#7D5164" "#9D4649" "#AA866C"

  my_pal <- c("#2D5992", "#478CB3", "#6D92A0", "#727786", "#7D5164", "#9D4649", "#AA866C")

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

  trade_by_continent$color <- my_pal[trade_by_continent$reporter_continent]

  d3po(trade_by_continent, width = 800, height = 600) %>%
    po_donut(daes(size = trade, group = reporter_continent, inner_radius = 0.3, color = color)) %>%
    po_labels(title = "Trade Share by Reporter Continent in 2023")
}

Run the code above in your browser using DataLab