The goal of jpwrapper is to provide a set of functions to customize Datawrapper charts from R. The functions take default values that incorporate the design choices for charts I create at The Jakarta Post.
The functions are as follow:
- jp_scale_y_c()
modifies the y-axis components such as breaks and
limits for continuous variable;
- jp_labs()
edits chart title, byline, alt text etc; and
- jp_theme()
customizes subtitle text color, grid lines, The Jakarta
Post’s logo, etc.
Currently, the package is compatible with only line, bar and column charts, as well as scatter plots. These are the chart types I mostly use at The Jakarta Post.
if (!require("devtools")) install_packages("devtools")
library(devtools)
devtools::install_github("dzulfiqarfr/jpwrapper")
jpwrapper builds on top of DataWrappr package (along many other dependencies), so you need to load both packages to customize a Datawrapper chart.
library(DatawRappr)
library(jpwrapper)
chart_id <- "abcD3" # Mock chart ID
jp_scale_y_c(
chart_id = chart_id,
limits = c(0, 200),
breaks = seq(0, 200, 40),
position = "left"
)
jp_labs(
chart_id = chart_id,
title = "West Java: COVID-19 deaths",
subtitle = paste0(
"Daily new confirmed deaths* by age group ",
"(seven-day moving average)"
),
notes = "*Between April 2, 2020, and Oct. 5, 2021",
source_name = "West Java administration",
source_url = "https://pikobar.jabarprov.go.id/",
byline = "@dzulfiqarfr",
jp_byline_prefix = FALSE,
alt_text = paste0(
"A line chart of confirmed COVID-19 deaths in West Java by age group. ",
"The chart shows that deaths among the elderly did not surge as ",
"significant as those among residents aged 59 years old or younger ",
"in July and August, when the delta variant drove the second wave. ",
"But the province has since recorded improvements."
)
)
jp_theme(
chart_id = chart_id,
labeling = "top",
logo = FALSE
)
This is not an official product of The Jakarta Post.
The package mainly uses the
dw_edit_chart()
function from the DatawRappr package. Read Datawrapper’s API
documentation here.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.