Title: | Access the Our World in Data Chart API |
---|---|
Description: | Retrieve data from the Our World in Data (OWID) Chart API <https://docs.owid.io/projects/etl/api/>. OWID provides public access to more than 5,000 charts focusing on global problems such as poverty, disease, hunger, climate change, war, existential risks, and inequality. |
Authors: | Christoph Scheuch [aut, cre, cph]
|
Maintainer: | Christoph Scheuch <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9001 |
Built: | 2025-03-03 22:23:11 UTC |
Source: | https://github.com/tidy-intelligence/r-owidapi |
Creates HTML code to embed an interactive chart from Our World in Data into an HTML document using an iframe.
owid_embed(url, width = "100%", height = "600px")
owid_embed(url, width = "100%", height = "600px")
url |
A character string containing the URL of the Our World in Data chart. Must begin with "https://ourworldindata.org/grapher/". |
width |
A character string specifying the width of the iframe. Default is "100%". |
height |
A character string specifying the height of the iframe. Default is "600px". |
A character string containing the HTML iframe to embed the chart.
owid_embed( "https://ourworldindata.org/grapher/co2-emissions-per-capita", width = "90%", height = "500px" )
owid_embed( "https://ourworldindata.org/grapher/co2-emissions-per-capita", width = "90%", height = "500px" )
Retrieves data from Our World in Data (OWID) by specifying a chart identifier or direct URL. Allows filtering by entities and time periods.
owid_get( chart_id = NULL, entities = NULL, start_date = NULL, end_date = NULL, url = NULL, use_column_short_names = TRUE, snake_case = TRUE )
owid_get( chart_id = NULL, entities = NULL, start_date = NULL, end_date = NULL, url = NULL, use_column_short_names = TRUE, snake_case = TRUE )
chart_id |
Character string specifying the chart identifier
(e.g., "life-expectancy"). Not required if |
entities |
Vector of entity codes (e.g., c("USA", "DEU")). If NULL, data for all available entities is returned. |
start_date |
Start date for filtering data. Can be a date string or a year. If NULL, starts from the earliest available data. |
end_date |
End date for filtering data. Can be a date string or a year. If NULL, ends with the latest available data. |
url |
Direct URL to an OWID dataset. If provided, |
use_column_short_names |
Logical. If TRUE (default), uses short column names. |
snake_case |
Logical. If TRUE (default), converts column names to lowercase. |
A tibble containing the requested OWID data.
# Download a full table owid_get("life-expectancy") # Download a table only for selected entities owid_get("life-expectancy", c("AUS", "AUT", "GER")) # Download a table only for selected time periods owid_get("life-expectancy", c("USA"), 1970, 1980) # Download daily data for selected time periods owid_get( "daily-covid-vaccination-doses-per-capita", "DEU", "2020-12-28", "2020-12-31" ) # Download a table by just providing an URL (with or without .csv) owid_get( url = paste0( "https://ourworldindata.org/grapher/civil-liberties-score-fh", "?tab=chart&time=earliest..2023&country=ARG~AUS~BWA~CHN~ALB~DEU" ) ) owid_get( url = paste0( "https://ourworldindata.org/grapher/civil-liberties-score-fh.csv", "?tab=chart&time=earliest..2023" ) )
# Download a full table owid_get("life-expectancy") # Download a table only for selected entities owid_get("life-expectancy", c("AUS", "AUT", "GER")) # Download a table only for selected time periods owid_get("life-expectancy", c("USA"), 1970, 1980) # Download daily data for selected time periods owid_get( "daily-covid-vaccination-doses-per-capita", "DEU", "2020-12-28", "2020-12-31" ) # Download a table by just providing an URL (with or without .csv) owid_get( url = paste0( "https://ourworldindata.org/grapher/civil-liberties-score-fh", "?tab=chart&time=earliest..2023&country=ARG~AUS~BWA~CHN~ALB~DEU" ) ) owid_get( url = paste0( "https://ourworldindata.org/grapher/civil-liberties-score-fh.csv", "?tab=chart&time=earliest..2023" ) )
Downloads the data catalog of Our World in Data (OWID) hosted on Datasette.
owid_get_catalog(snake_case = TRUE)
owid_get_catalog(snake_case = TRUE)
snake_case |
Logical. If TRUE (default), converts column names to lowercase. |
A tibble containing the OWID catalog.
# Download a full table owid_get_catalog()
# Download a full table owid_get_catalog()
Retrieves the metadata for a data set from Our World in Data (OWID) by specifying a chart identifier or direct URL.
owid_get_metadata(chart_id = NULL, url = NULL)
owid_get_metadata(chart_id = NULL, url = NULL)
chart_id |
Character string specifying the chart identifier
(e.g., "life-expectancy"). Not required if |
url |
Direct URL to an OWID chart. If provided, |
A list containing the requested OWID metadata.
# Download metadata using a data set owid_get_metadata("life-expectancy") # Download metadata using an url owid_get_metadata( url = "https://ourworldindata.org/grapher/civil-liberties-score-fh" )
# Download metadata using a data set owid_get_metadata("life-expectancy") # Download metadata using an url owid_get_metadata( url = "https://ourworldindata.org/grapher/civil-liberties-score-fh" )
This function creates an HTML output element for embedding Our World in Data (OWID) charts in a Shiny application. It should be used in the UI definition of your Shiny app.
owid_output(id) owid_server(id, url, width = "100%", height = "600px")
owid_output(id) owid_server(id, url, width = "100%", height = "600px")
id |
Character string. The ID of the output element. |
url |
Character string. The URL of the OWID chart to embed. |
width |
Character string. The width of the chart (default: "100%"). |
height |
Character string. The height of the chart (default: "600px"). |
A Shiny HTML output element where the OWID chart will be rendered.
library(shiny) ui <- fluidPage( owid_output("gdp_chart"), owid_output("co2_chart") ) server <- function(input, output) { owid_server( "gdp_chart", "https://ourworldindata.org/grapher/gdp-per-capita-worldbank?tab=line" ) owid_server( "co2_chart", "https://ourworldindata.org/grapher/co2-emissions-per-capita", height = "500px" ) } shinyApp(ui = ui, server = server)
library(shiny) ui <- fluidPage( owid_output("gdp_chart"), owid_output("co2_chart") ) server <- function(input, output) { owid_server( "gdp_chart", "https://ourworldindata.org/grapher/gdp-per-capita-worldbank?tab=line" ) owid_server( "co2_chart", "https://ourworldindata.org/grapher/co2-emissions-per-capita", height = "500px" ) } shinyApp(ui = ui, server = server)
This function searches for a vector of keywords within specified columns of an OWID catalog data frame. If no columns are specified, it searches all character and factor columns.
owid_search(data, keywords, columns = NULL)
owid_search(data, keywords, columns = NULL)
data |
A data frame, typically obtained from owid_get_catalog. |
keywords |
A character vector of one or more keywords to search for. The search is case-insensitive. |
columns |
An optional character vector of column names to search within. If NULL (default), all character and factor columns are searched. |
A filtered data frame containing only rows that match at least one of the keywords in at least one of the specified columns.
# Get the OWID catalog catalog <- owid_get_catalog() # Search for climate or carbon in all text columns owid_search(catalog, c("climate", "carbon")) # Search only in the title column owid_search(catalog, c("climate", "carbon"), c("title"))
# Get the OWID catalog catalog <- owid_get_catalog() # Search for climate or carbon in all text columns owid_search(catalog, c("climate", "carbon")) # Search only in the title column owid_search(catalog, c("climate", "carbon"), c("title"))