Chapter 3 Plotly
(Computer Labs 2B+)

A key component of data science is the effective and informative visualisation of data. Throughout Computer Labs 2B to 4B, we will be using the plotly R package (Sievert 2020) to create data visualisations in RStudio that are dynamic and interactive.

You will learn how to create various interactive graphs with plotly, such as the one shown below (which uses data from the palmerpenguins (Horst, Hill, and Gorman 2020) R package).

A few key aspects of this plotly graph which separate it from the static graphs which can be produced using built-in R functions are:

  • If you hover over the data points in the graph, you can see information about the data.
  • If you click on the legend items, you can dynamically filter out categories - just re-click the item to bring the corresponding data back.
  • You can left-click, drag a box and then release the mouse button within the graph, to zoom in on a specific portion of the graph.
  • As you interact with the graph, the axes will dynamically adjust.

Take a look at this video featuring the late Hans Rosling (a world-renowned physician and an engaging public speaker) - by the end of Computer Lab 4B you will have the skills to create a similar interactive and animated plot!

6

References

Horst, Allison Marie, Alison Presmanes Hill, and Kristen B Gorman. 2020. Palmerpenguins: Palmer Archipelago (Antarctica) Penguin Data. https://doi.org/10.5281/zenodo.3960218.
Sievert, Carson. 2020. Interactive Web-Based Data Visualization with r, Plotly, and Shiny. Chapman; Hall/CRC. https://plotly-r.com.

  1. BBC. (2010, Nov. 26). Hans Rosling’s 200 Countries, 200 Years, 4 Minutes - The Joy of Stats - BBC 4 [Video]. YouTube. https://www.youtube.com/watch?v=jbkSRLYSojo↩︎