Testing d3

*Blog post
2022
Graphical display
Incomplete page
Author

Steve Simon

Published

June 1, 2022

I am interested in developing some visualization applications using d3. You can run d3 from within R Markdown.

This is an example that I borrowed from Section 15.5 of R Markdown Cookbook by Yihui Xie, Christophe Dervieus, and Emily Riederer.

First, load the package r2d3 to set up the d3 engine for knitr automatically:

library(r2d3)
Warning: package 'r2d3' was built under R version 4.5.1
r2d3 should be run under RStudio v1.2 or higher. Please update at:
https://www.rstudio.com/products/rstudio/download/

Now we can generate data in R, pass it to D3, and draw the chart:

svg.selectAll('rect')
  .data(data)
  .enter()
    .append('rect')
      .attr('width', function(d) { return d * 672; })
      .attr('height', '10px')
      .attr('y', function(d, i) { return i * 16; })
      .attr('fill', options.color);

An earlier version of this page was published on new.pmean.com.