Interactive Charts & Maps
Maya's one neighbourhood bakery, the shop whose Q1 numbers you turned into a report table earlier in this track, did so well that she opened five more. She now runs six coffee-and-pastry shops across the city, and a printed bar chart no longer keeps up with her questions. Which shop is that tall bar again? What exactly did the quiet one take last month? Where are they on the map?
A static chart is a photograph: it shows the shape and then stops answering. An interactive chart is a conversation. You hover a point and it tells you which shop and the exact dollars; you drag a box around a crowded corner and it zooms in; you pan a map and the streets move under your shops. Move the Area filter on the dashboard below and watch every number and chart answer at once. That responsiveness is what this lesson builds, one chart and one map at a time.
By the end of this lesson you will be able to:
- Say what interactivity actually adds to a chart, and when it helps versus when it hurts
- Turn an ordinary ggplot into an interactive plotly chart with one line,
ggplotly() - Put your data on a leaflet map: a street basemap with a marker and a popup for every row
- Choose between an interactive and a static chart by where it has to live
Prerequisites: you can run R and load a package with library(), and you have built a ggplot (data, then aes(), then a geom) in the ggplot2 course. Every new term is defined as it appears.
What interactivity actually buys you
A good static chart answers the big-picture question well: do busier shops make more money? Maya can read that off a scatter in a second. But the moment she asks a pointed question, a static picture goes quiet. Three things interactivity adds, each fixing a real limit of a printed chart:
- Hover reveals the exact value and the identity behind a mark. Instead of "that dot is around forty-something thousand," she hovers and reads
Old Town: 240 customers/day, $53,000. The label was always in the data; hover just surfaces it on demand instead of cluttering the page. - Zoom and pan let her explore density. When ten shops pile into one corner of a scatter, she drags a box around them and the chart zooms in so she can tell them apart.
- A live map lets her drag and zoom the city itself, instead of squinting at a fixed image.
First, the data. Each lesson runs in a fresh R session, so we build Maya's six shops right here (run this once):
Everything we draw, the chart and the map, comes from this one frame. Start with the plain static chart Maya already knows how to make: customers across the bottom, revenue up the side, one point per shop. It answers the big question (busier shops do take more) but it cannot tell you which dot is which:
That p is our starting point. In the next step we make it talk back.