| Title: | Fast and Beautiful Interactive Visualization for 'Markdown' and 'Shiny' |
|---|---|
| Description: | Apache licensed alternative to 'Highcharter' which provides functions for both fast and beautiful interactive visualization for 'Markdown' and 'Shiny'. |
| Authors: | Mauricio Vargas Sepulveda [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-1017-7574>), John Coene [aut], Ariel Alvarado [ctb], Sylvain Lesage [ctb], Curran Kelleher [ctb], Fernando Becerra [ctb], Natural Earth [dtc], R Consortium [fnd] (Funded for the 2016-2017 ISC grants cycle) |
| Maintainer: | Mauricio Vargas Sepulveda <[email protected]> |
| License: | Apache License (>= 2.0) |
| Version: | 1.0.2 |
| Built: | 2026-05-10 13:13:34 UTC |
| Source: | https://github.com/pachadotdev/d3po |
Output and render functions for using d3po within Shiny applications and interactive Rmd documents.
d3po_output(output_id, width = "100%", height = "400px") render_d3po(expr, env = parent.frame(), quoted = FALSE) d3po_proxy(id, session = shiny::getDefaultReactiveDomain())d3po_output(output_id, width = "100%", height = "400px") render_d3po(expr, env = parent.frame(), quoted = FALSE) d3po_proxy(id, session = shiny::getDefaultReactiveDomain())
output_id |
output variable to read from |
width, height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a d3po object |
env |
The environment in which to evaluate |
quoted |
Is |
id |
Id of plot to create a proxy of. |
session |
A valid shiny session. |
Creates a basic 'htmlwidget' object for 'Shiny' and interactive documents
Aesthetics of the chart.
daes(x, y, ...)daes(x, y, ...)
x |
x-axis mapping. |
y |
y-axis mapping. |
... |
Other aesthetic mappings. See the 'Aesthetics' section. |
Aesthetics for the plots such as axis (x,y), group, color and/or size
Valid aesthetics (depending on the geom)
x, y: cartesian coordinates.
group: grouping data.
subgroup: subgrouping data (for treemaps).
name: name data.
color: color of geom.
size: size of geom.
stack: TRUE or FALSE to indicate if the geom should be stacked (for bar charts).
tiling: "squarify" (default), "dice", "slice", "slice-dice" (for treemaps).
layout: "fr", "kk", or any other supported in igraph to set the geom layout (for network charts).
gradient: TRUE or FALSE to indicate if color should be treated as a gradient palette (for geomaps).
sort: ordering hint for discrete categories. Accepts one of
"asc-x", "desc-x" (sort by the numeric x/value), or
"asc-y", "desc-y" (sort by the category/label). Use "none" to
keep input order.
National boundaries for all countries in the 'Natural Earth' repository. The topology has been simplified for better performance in web visualizations and reduced file size.
nationalnational
An sf object with 202 observations and 4 variables.
continent: Continent name.
country: Country name.
country_iso: ISO 3166-1 alpha-3 country code.
geometry: Simple feature geometry column.
Derived from https://www.naturalearthdata.com/.
national[national$country_iso == "GBR", ]national[national$country_iso == "GBR", ]
Plot an area chart.
po_area(d3po, ..., data = NULL, inherit_daes = TRUE)po_area(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
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 = "Cigars of the Pharaoh")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_by_continent, width = 800, height = 600) %>% po_area(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" ) }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 = "Cigars of the Pharaoh")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_by_continent, width = 800, height = 600) %>% po_area(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" ) }
Draw a bar chart.
po_bar(d3po, ..., data = NULL, inherit_daes = TRUE)po_bar(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
if (interactive()) { trade_by_continent <- d3po::trade trade_by_continent <- aggregate( trade ~ reporter_continent, data = d3po::trade, FUN = sum ) # Assign colors to continents my_pal <- tintin::tintin_pal()(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_by_continent, width = 800, height = 600) %>% po_bar(daes(x = reporter_continent, y = trade, color = my_pal)) %>% po_labels( x = "Continent", y = "Trade (USD billion)", title = "Total Trade by Reporter Continent in 2023" ) }if (interactive()) { trade_by_continent <- d3po::trade trade_by_continent <- aggregate( trade ~ reporter_continent, data = d3po::trade, FUN = sum ) # Assign colors to continents my_pal <- tintin::tintin_pal()(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_by_continent, width = 800, height = 600) %>% po_bar(daes(x = reporter_continent, y = trade, color = my_pal)) %>% po_labels( x = "Continent", y = "Trade (USD billion)", title = "Total Trade by Reporter Continent in 2023" ) }
Draw a boxplot.
po_box(d3po, ..., data = NULL, inherit_daes = TRUE)po_box(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
if (interactive()) { trade_continent <- d3po::trade trade_continent <- aggregate( trade ~ reporter_continent + reporter, data = trade_continent, FUN = sum ) my_pal <- tintin::tintin_pal(option = "Destination Moon")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_continent, width = 800, height = 600) %>% po_box(daes( x = reporter_continent, y = trade, color = my_pal, tooltip = reporter_continent )) %>% po_labels( x = "Continent", y = "Trade (USD billion)", title = "Trade Distribution by Reporter Continent" ) }if (interactive()) { trade_continent <- d3po::trade trade_continent <- aggregate( trade ~ reporter_continent + reporter, data = trade_continent, FUN = sum ) my_pal <- tintin::tintin_pal(option = "Destination Moon")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_continent, width = 800, height = 600) %>% po_box(daes( x = reporter_continent, y = trade, color = my_pal, tooltip = reporter_continent )) %>% po_labels( x = "Continent", y = "Trade (USD billion)", title = "Trade Distribution by Reporter Continent" ) }
Plot a donut
po_donut(d3po, ..., data = NULL, inherit_daes = TRUE)po_donut(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
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) 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") }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) 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") }
Show/hide the download button.
po_download(d3po, show = TRUE)po_download(d3po, show = TRUE)
d3po |
A 'd3po' or 'd3proxy' object. |
show |
Logical indicating whether to show (TRUE) or hide (FALSE) the download button. |
Appends download button settings to an 'htmlwidgets' object
Edit the font used in a chart.
po_font(d3po, family = "Fira Sans", size = 16, transform = "none")po_font(d3po, family = "Fira Sans", size = 16, transform = "none")
d3po |
Either the output of |
family |
family font to use ("Roboto", "Merriweather", etc.). |
size |
size to use (10, 11, 12, etc. overrides auto-sizing). |
transform |
transformation to use for the title ("lowercase", "uppercase", "capitalize", "none"). |
Appends custom font to an 'htmlwidgets' object
Precompute formatted label columns from expressions and attach them to the
widget data. Accepts named expressions like x = round(varx, 2) or
y = format(varY, big.mark = ","). The formatted columns are added to
d3po$x$data with names __label_<name> and registered in
d3po$x$formatted_cols for the renderer to use.
po_format(d3po, ...)po_format(d3po, ...)
d3po |
Either the output of |
... |
Named formatting expressions (as quosures). Each name should
correspond to an aesthetic (e.g. |
Plot a geomap using sf spatial objects
po_geomap(d3po, ..., data = NULL, inherit_daes = TRUE, limits = NULL)po_geomap(d3po, ..., data = NULL, inherit_daes = TRUE, limits = NULL)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
limits |
A numeric vector of length 2 specifying the minimum and maximum values for the color scale. |
an 'htmlwidgets' object with the desired interactive plot
if (interactive()) { world <- d3po::national # Fix geometries that cross the antimeridian (date line) to avoid horizontal lines # This affects Russia, Fiji, and other countries spanning the 180° meridian world$geometry <- sf::st_wrap_dateline(world$geometry, options = c("WRAPDATELINE=YES")) total_trade <- d3po::trade[ d3po::trade$year == 2023L, c("reporter", "reporter_continent", "trade") ] total_trade <- aggregate(trade ~ reporter, data = total_trade, FUN = sum) colnames(total_trade) <- c("country", "trade") world <- merge( world, total_trade, by = "country", all.x = TRUE, all.y = FALSE ) my_pal <- tintin::tintin_pal(option = "The Calculus Affair")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(world, width = 800, height = 600) %>% po_geomap(daes(group = country, size = trade, color = my_pal, tooltip = country)) %>% po_labels(title = "Trade Volume by Country in 2023") }if (interactive()) { world <- d3po::national # Fix geometries that cross the antimeridian (date line) to avoid horizontal lines # This affects Russia, Fiji, and other countries spanning the 180° meridian world$geometry <- sf::st_wrap_dateline(world$geometry, options = c("WRAPDATELINE=YES")) total_trade <- d3po::trade[ d3po::trade$year == 2023L, c("reporter", "reporter_continent", "trade") ] total_trade <- aggregate(trade ~ reporter, data = total_trade, FUN = sum) colnames(total_trade) <- c("country", "trade") world <- merge( world, total_trade, by = "country", all.x = TRUE, all.y = FALSE ) my_pal <- tintin::tintin_pal(option = "The Calculus Affair")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(world, width = 800, height = 600) %>% po_geomap(daes(group = country, size = trade, color = my_pal, tooltip = country)) %>% po_labels(title = "Trade Volume by Country in 2023") }
Edit labels positioning in a treemap.
po_labels( d3po, x = NULL, y = NULL, title = NULL, subtitle = NULL, labels = NULL, align = "left-top" )po_labels( d3po, x = NULL, y = NULL, title = NULL, subtitle = NULL, labels = NULL, align = "left-top" )
d3po |
Either the output of |
x |
Optional x-axis label. |
y |
Optional y-axis label. |
title |
Optional title for the chart. |
subtitle |
Optional subtitle for the chart. |
labels |
Optional character vector or JavaScript function for custom label fields for treemaps. |
align |
Label alignment for treemaps. Must be one of "left-top", "center-middle", or "right-top". |
Appends custom labels to an 'htmlwidgets' object
Plot an line chart.
po_line(d3po, ..., data = NULL, inherit_daes = TRUE)po_line(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
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) 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" ) }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) 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" ) }
Draw a network graph showing relationships between entities. Requires an igraph object with nodes (vertices) and links (edges). Node size can represent counts or other metrics.
po_network(d3po, ..., data = NULL, inherit_daes = TRUE)po_network(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
Appends nodes arguments to a network-specific 'htmlwidgets' object
if (interactive()) { trade_network <- d3po::trade[d3po::trade$year == 2023L, ] trade_network <- aggregate( trade ~ reporter_iso + partner_iso + reporter_continent + partner_continent, data = trade_network, FUN = sum ) # subset to 10 largest connection per reporter country trade_network <- do.call( rbind, lapply( split(trade_network, trade_network$reporter_iso), function(df) head(df[order(-df$trade), ], 10) ) ) # Create vertex (node) attributes for coloring and sizing # Get unique countries with their continents and trade volumes vertices <- unique(rbind( data.frame( name = trade_network$reporter_iso, continent = trade_network$reporter_continent, stringsAsFactors = FALSE ), data.frame( name = trade_network$partner_iso, continent = trade_network$partner_continent, stringsAsFactors = FALSE ) )) # Remove duplicates vertices <- vertices[!duplicated(vertices$name), ] # Calculate total trade volume per country (as reporter) trade_volume <- aggregate(trade ~ reporter_iso, data = trade_network, FUN = sum) colnames(trade_volume) <- c("name", "trade_volume") # Merge trade volume with vertices vertices <- merge(vertices, trade_volume, by = "name", all.x = TRUE) vertices$trade_volume[is.na(vertices$trade_volume)] <- 0 # Assign colors to continents my_pal <- tintin::tintin_pal(option = "The Blue Lotus")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) # Add color column based on continent vertices$color <- my_pal[vertices$continent] # Create igraph object with vertex attributes g <- graph_from_data_frame(trade_network, directed = TRUE, vertices = vertices) # Create the network visualization d3po(g, width = 800, height = 600) %>% po_network(daes(size = trade_volume, color = color, layout = "fr")) %>% po_labels(title = "Trade Network by Country in 2023") }if (interactive()) { trade_network <- d3po::trade[d3po::trade$year == 2023L, ] trade_network <- aggregate( trade ~ reporter_iso + partner_iso + reporter_continent + partner_continent, data = trade_network, FUN = sum ) # subset to 10 largest connection per reporter country trade_network <- do.call( rbind, lapply( split(trade_network, trade_network$reporter_iso), function(df) head(df[order(-df$trade), ], 10) ) ) # Create vertex (node) attributes for coloring and sizing # Get unique countries with their continents and trade volumes vertices <- unique(rbind( data.frame( name = trade_network$reporter_iso, continent = trade_network$reporter_continent, stringsAsFactors = FALSE ), data.frame( name = trade_network$partner_iso, continent = trade_network$partner_continent, stringsAsFactors = FALSE ) )) # Remove duplicates vertices <- vertices[!duplicated(vertices$name), ] # Calculate total trade volume per country (as reporter) trade_volume <- aggregate(trade ~ reporter_iso, data = trade_network, FUN = sum) colnames(trade_volume) <- c("name", "trade_volume") # Merge trade volume with vertices vertices <- merge(vertices, trade_volume, by = "name", all.x = TRUE) vertices$trade_volume[is.na(vertices$trade_volume)] <- 0 # Assign colors to continents my_pal <- tintin::tintin_pal(option = "The Blue Lotus")(7) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) # Add color column based on continent vertices$color <- my_pal[vertices$continent] # Create igraph object with vertex attributes g <- graph_from_data_frame(trade_network, directed = TRUE, vertices = vertices) # Create the network visualization d3po(g, width = 800, height = 600) %>% po_network(daes(size = trade_volume, color = color, layout = "fr")) %>% po_labels(title = "Trade Network by Country in 2023") }
Plot a pie
po_pie(d3po, ..., data = NULL, inherit_daes = TRUE)po_pie(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
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) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_by_continent, width = 800, height = 600) %>% po_pie(daes(size = trade, group = reporter_continent, color = my_pal)) %>% po_labels(title = "Trade Share by Reporter Continent in 2023") }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) names(my_pal) <- c( "Africa", "Antarctica", "Asia", "Europe", "North America", "Oceania", "South America" ) d3po(trade_by_continent, width = 800, height = 600) %>% po_pie(daes(size = trade, group = reporter_continent, color = my_pal)) %>% po_labels(title = "Trade Share by Reporter Continent in 2023") }
Plot an scatter chart.
po_scatter(d3po, ..., data = NULL, inherit_daes = TRUE)po_scatter(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
if (interactive()) { # Create a wide dataset with x = 2019 and y = 2023 trade values trade_wide_2019 <- d3po::trade[d3po::trade$year == 2019L, c("reporter", "trade")] trade_wide_2019 <- aggregate(trade ~ reporter, data = trade_wide_2019, FUN = sum) trade_wide_2023 <- d3po::trade[d3po::trade$year == 2023L, c("reporter", "trade")] trade_wide_2023 <- aggregate(trade ~ reporter, data = trade_wide_2023, FUN = sum) trade_wide <- merge( trade_wide_2019, trade_wide_2023, by = "reporter", suffixes = c("_2019", "_2023") ) my_pal <- tintin::tintin_pal(option = "red_rackhams_treasure")(7) d3po(trade_wide, width = 800, height = 600) %>% po_scatter(daes(x = trade_2019, y = trade_2023, group = reporter, color = my_pal)) %>% po_labels( x = "Trade in 2019 (USD billion)", y = "Trade in 2023 (USD billion)", title = "Trade Volume by Country in 2019 and 2023" ) }if (interactive()) { # Create a wide dataset with x = 2019 and y = 2023 trade values trade_wide_2019 <- d3po::trade[d3po::trade$year == 2019L, c("reporter", "trade")] trade_wide_2019 <- aggregate(trade ~ reporter, data = trade_wide_2019, FUN = sum) trade_wide_2023 <- d3po::trade[d3po::trade$year == 2023L, c("reporter", "trade")] trade_wide_2023 <- aggregate(trade ~ reporter, data = trade_wide_2023, FUN = sum) trade_wide <- merge( trade_wide_2019, trade_wide_2023, by = "reporter", suffixes = c("_2019", "_2023") ) my_pal <- tintin::tintin_pal(option = "red_rackhams_treasure")(7) d3po(trade_wide, width = 800, height = 600) %>% po_scatter(daes(x = trade_2019, y = trade_2023, group = reporter, color = my_pal)) %>% po_labels( x = "Trade in 2019 (USD billion)", y = "Trade in 2023 (USD billion)", title = "Trade Volume by Country in 2019 and 2023" ) }
Manually set colors used by D3po for axis/axis-labels/title, tooltips/download menu background, and chart background. This allows you to override page themes (Tabler/Shiny) and force D3po to render with readable contrast.
po_theme(d3po, axis = NULL, tooltips = NULL, background = NULL)po_theme(d3po, axis = NULL, tooltips = NULL, background = NULL)
d3po |
Either the output of |
axis |
Hex color string for axis lines and axis/label/title fill (e.g. "#fff"). |
tooltips |
Hex color string for tooltip / download menu background (e.g. "#000"). |
background |
Hex color string for chart background (e.g. "#fff"). |
Appends theme settings to an 'htmlwidgets' object
Set a custom tooltip template for a chart. The template can be a literal
string (e.g. <b>{name}</b><br>Value: {value}) which will be evaluated
server-side by substituting column values.
po_tooltip(d3po, template)po_tooltip(d3po, template)
d3po |
Either the output of |
template |
A character string template or formatter expression. |
Appends tooltip settings to an 'htmlwidgets' object
Plot a treemap
po_treemap(d3po, ..., data = NULL, inherit_daes = TRUE)po_treemap(d3po, ..., data = NULL, inherit_daes = TRUE)
d3po |
Either the output of |
... |
Aesthetics, see |
data |
Any dataset to use for plot, overrides data passed
to |
inherit_daes |
Whether to inherit aesthetics previous specified. |
an 'htmlwidgets' object with the desired interactive plot
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) 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") }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) 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") }
Subnational boundaries for the available countries in the 'Natural Earth' repository. The topology has been simplified for better performance in web visualizations and reduced file size. Subnational regions include states, provinces, and equivalent administrative divisions.
subnationalsubnational
An sf object with 4,596 observations and 6 variables.
continent: Continent name.
country: Country name.
region: Subnational region name.
country_iso: ISO 3166-1 alpha-3 country code.
region_iso: ISO 3166-2 subnational region code.
geometry: Simple feature geometry column.
Derived from https://www.naturalearthdata.com/.
subnational[subnational$country_iso == "GBR", ]subnational[subnational$country_iso == "GBR", ]
Bilateral trade flows between countries for the years 2019 and 2023. Trade values are expressed in USD billion dollars.
tradetrade
A data frame with 5,223 observations and 8 variables.
year: Year of the trade data (2019 or 2023).
reporter_continent: Continent of the reporting country.
partner_continent: Continent of the partner country.
reporter: Name of the reporting country.
partner: Name of the partner country.
reporter_iso: ISO 3166-1 alpha-3 code of the reporting country.
partner_iso: ISO 3166-1 alpha-3 code of the partner country.
trade: Trade value in USD billion dollars. Reporter (importer-side) figures are used.
Derived from the UN Comtrade database (https://comtrade.un.org/).
head(trade[trade$year == 2023L & trade$reporter_iso == "gbr", ])head(trade[trade$year == 2023L & trade$reporter_iso == "gbr", ])