The goal of this vignette is to show some examples of (hopefully) useful, interesting or fun notebooks usable with
Yes, I know, pie charts are mostly bad. But the following notebook allows the creation of interactive pie or ‘donut’ charts, with slices optionally ‘draggable’ to rearrange their order.
Here is a small example. To display the chart we have to
include both the
draw cells, and we hide
draw as it is only useful to render the plot. We pass our data as a data frame with
The following notebook generates animated “bar chart race” charts.
To use it from
robservable you have to place your data in a data frame with the following columns :
id: identifier (country, city, brand…)
date: observation date (can be any number or character : year, day…)
value: value for that
Optionally, if you want the displayed date value to be different than the one used in your dataset (for example if you iterate over monthly data but prefer to only display the year), you can add a corresponding
library(readr) library(dplyr) library(tidyr) ## Load Covid-19 data from Johns Hopkins Github repository d <- read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv") ## Reformat data d <- d %>% select(-`Province/State`, -Lat, -Long) %>% rename(id = `Country/Region`) %>% group_by(id) %>% summarise(across(everything(), sum)) %>% pivot_longer(-id, names_to = "date") %>% mutate(date = as.character(lubridate::mdy(date))) ## Filter out data d <- d %>% group_by(date) %>% filter(value > 0 & (n() - row_number(value)) <= 12) %>% arrange(date)
We can then generate the chart with the following
robservable call. Note that we have to include several cells : the chart itself, the
draw cell which updates it, the
date play/pause control, and the CSS
## Generate chart robservable( "https://observablehq.com/@juba/bar-chart-race", include = c("viewof date", "chart", "draw", "styles"), hide = "draw", input = list( data = d, title = "COVID-19 deaths", subtitle = "Cumulative number of COVID-19 deaths by country", source = "Source : Johns Hopkins University" ), width = 700, height = 710 )
The following notebook allows to create a Voronoi diagram on a map background.
Here we load data about the location of engineering schools in France in 2020 (Source : Onisep).
And we display it as a Voronoi diagram by calling
robservable the following way. Note that we have to include both
draw cells for the map to be rendered (but we hide
draw as it doesn’t display anything by itself).
map_url <- "https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/regions-version-simplifiee.geojson" robservable( "@juba/reusable-voronoi-map", include = c("chart", "draw"), hide = "draw", input = list( contour = map_url, contour_width = 1, data = d, longitude_var = "longitude (X)", latitude_var = "latitude (Y)", point_radius = 1.5, zoom = TRUE ), width = 600, height = 600 )
You can zoom and pan the map.
The following notebook makes bivariate choropleth maps with zoom and tooltips.
We first load some data from the USA.county.data Github project, only keep California counties, and select two of the available variables.
Then we can call
robservable to load the notebook, render only
draw (both are needed for the map to show), hide
draw and update a bunch of cells values via the
input named list. You can refer to the notebook for an explanation of the different values.
robservable( "@juba/reusable-bivariate-choropleth", include = c("chart", "draw"), hide = "draw", input = list( data = d, data_id = "name_16", data_name = "name_16", data_var1 = "Graduate", data_var2 = "<High.School", map = "https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/california-counties.geojson", map_object = "geometry", map_id_property = "name", legend_position = "bottomleft" ), width = 800, height = 500 )