Chapter 3 Plotly
(Computer Labs 1B+)

A key component of data science is the effective and informative visualisation of data. Throughout Computer Labs 1B to 4B, we will be using the plotly R package (Sievert 2020) to create data visualisations 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 in base R 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 reclick the item to bring the corresponding data back.
  • You can left-click and drag a box 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 these computer labs you will have the skills to create a similar interactive and animated plot!

5

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↩︎