knitr::opts_chunk$set(echo = FALSE)

library(tidyverse)
library(robservable)

Canvas

Before canvas.

robservable("@mbostock/liquidfun", include = "canvas", height = 600, width = 500)

After canvas.

Multi line plot

With gapminder data, graph from https://observablehq.com/@d3/multi-line-chart.

library(gapminder)
data(gapminder)
series <- purrr::map(unique(gapminder$country), ~{
  name <- .x
  values <- gapminder %>% filter(country == .x) %>% pull(lifeExp)
  list(name = name, values = values)
})
dates <- sort(unique(gapminder$year))
dates <- as.Date(as.character(dates), format = "%Y")
#dates <- (dates - 1970) * 365 * 24 * 3600 * 1000

df <- list(
  y = "Life expectancy",
  series = series,
  dates = to_js_date(dates)
)

robservable(
  "@d3/multi-line-chart",
  include = "chart",
  input = list(data = df, height = 1000),
  width = 500,
  height = 1000
)

And some text after.



Try the robservable package in your browser

Any scripts or data that you put into this service are public.

robservable documentation built on June 28, 2022, 5:06 p.m.