Chapter 4 Interact

For a few years now, you have been able to use Javascript to create interactive plots to include on websites. These plots respond to actions from your mouse. When you scroll over a point, for example, some information about the point might show up, or when you click on a marker on a map, you might get a pop-up box with some information.

More recently, R packages have been developed that allow you to create these interactive visualizations directly from R. Many of these packages were developed by members of the R Studio team in a collection of packages called htmlwidgets (Vaidyanathan et al. 2018Vaidyanathan, Ramnath, Yihui Xie, JJ Allaire, Joe Cheng, and Kenton Russell. 2018. Htmlwidgets: HTML Widgets for R. Once you’ve mastered how to plot in R with ggplot2 and how to map with sf, some of these packages are almost embarrasingly easy to use to create really fantastic data visualizations.

You can use these interactive visualizations on your own computer to explore your data. You can also include them in webpages and post them for others to see. In the “Report” section, I’ll talk more about how you can create reports using R to share or post as webpages. While you’re developing a visualization, you’ll be able to check it out in the “Viewer” pane in R Studio, just like you can see plots in the “Plots” pane.