Learn R Programming

d3po (version 1.0.3)

po_line: Line

Description

Plot an line chart.

Usage

po_line(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
  trade_by_continent <- aggregate(
    trade ~ year + reporter_continent,
    data = trade_by_continent,
    FUN = sum
  )

  # Assign colors to continents
  # my_pal <- tintin::tintin_pal(option = "The Broken Ear")(7)
  # [1] "#749972" "#7EA691" "#8EBCC5" "#9DB457" "#A8C17F" "#BBCC4D" "#C7D88F"

  my_pal <- c("#749972", "#7EA691", "#8EBCC5", "#9DB457", "#A8C17F", "#BBCC4D", "#C7D88F")

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

  d3po(trade_by_continent, width = 800, height = 600) %>%
    po_line(daes(x = year, y = trade, group = reporter_continent, color = my_pal)) %>%
    po_labels(
      x = "Year",
      y = "Trade (USD billion)",
      title = "Trade Distribution by Reporter Continent in 2019 and 2023"
    )
}

Run the code above in your browser using DataLab