install.packages('plotly')Interactivity
Due: Nov 16 by 11:59pm
Weight: This assignment is worth 1% of your final grade.
Purpose: The purpose of this assignment is to see what interactivity adds to a chart (and what it costs), then try two ways of getting there: converting a ggplot with plotly, and having Claude build a chart from scratch in D3, the JavaScript library behind most of the interactive charts you see online. Along the way, you will practice checking whether an interactive chart still says what the static one did.
Assessment: This assignment is graded using a check system:
- ✔+ (110%): Responses shows phenomenal thought and engagement with the course content. I will not assign these often.
- ✔ (100%): Responses are thoughtful, well-written, and show engagement with the course content. This is the expected level of performance.
- ✔− (50%): Responses are hastily composed, too short, and/or only cursorily engages with the course content. This grade signals that you need to improve next time. I will hopefully not assign these often.
Notice that this is essentially a pass/fail system. I’m not grading your writing ability and I’m not counting the number of words you write - I’m looking for thoughtful engagement. One or two sentences is not enough. Write at least a paragraph and show me that you did the readings assigned.
1. Get Organized
Open your course repo (eda-f26/eda-netID) in Positron using File › Open Folder - open the folder itself, not a file inside it. If you haven’t cloned your course repo yet, follow the steps in HW1 first.
Everything for this assignment lives in the hw11 folder. Open the hw11.qmd file inside it - that’s the only file you need to edit. Take notes and write example code under the “Begin notes here” heading as you go through the readings and exercises below, then write your reflection under the “Reflection” heading at the end.
2. Read & Practice
The readings listed below are broken into two groups:
- Design principles
- Coding techniques to implement those principles
Design principles
An interactive chart lets the reader do something a static chart can’t: hover for exact values, filter to the part they care about, zoom, or scroll through a story one step at a time. That can make a chart much richer, but it can also be decoration, or hide the main point behind a mouse movement. This week, read with one question in mind: what does the interaction let me do that a static chart wouldn’t?
To get started, find an article online that has some interactive charts. I recommend The Pudding - almost all of their articles blend text, data, and interactive charts (e.g. check out Are Pop Lyrics Getting More Repetitive?). Choose an article you find interesting, and feel free to use one from a different site.
Coding techniques
There are two routes to an interactive chart in this assignment. The first is the quick one: the plotly package converts a ggplot into an interactive chart with a single function, ggplotly(). The second is how most professional interactive charts are made: D3 is a JavaScript library that draws charts directly in the browser, and it can do things ggplot can’t. We won’t learn D3 in this course, but you will direct Claude to build a chart with it and see what that looks like.
- Plotly for R: Interactive web-based data visualization with R, plotly, and shiny - skim the chapter on
ggplotly() - D3: What is D3? - just the opening page
- D3 Graph Gallery: Browse the gallery to see what’s possible
Install this package before you start:
3. Study a good interactive
Read through your article carefully, then put notes in your hw11.qmd file under the “Study a good interactive” heading. Add a link to the article, then answer these questions:
- What was one main conclusion or point the author made?
- Pick one interactive chart from the article. What can the reader do with it, and could the same point have been made with a static chart? What would be lost?
- Was there anything you could critique about the article or its charts (e.g., a hover that hid something important, or interaction that was just for show)?
4. Make a chart interactive with plotly
Start from a static ggplot chart. It can be any chart you’ve made so far this semester (in class, in a previous homework, or for your project). If you copy it from somewhere else, don’t forget to copy any data files it needs.
Ask Claude Code to make an interactive version of it using ggplotly(). The core of the code is just this:
library(plotly)
ggplotly(plot)Then check it, because ggplotly() is a translation of your chart, and translations lose things:
- Check the tooltips. Hover over several points. Do they show the right variables, in sensible units and formats? By default, plotly often shows raw aesthetic names (
x,y,colour) or unrounded numbers. Fix them so a reader could understand them without seeing your code. - Check what got lost. Compare it to the static version. Do the title, subtitle, caption, annotations, and fonts all survive? Anything that vanished or moved?
- Check that interactivity earns its place. Is the interactive version actually better than the static one? If not, say so - that’s a legitimate finding, not a failed assignment.
In your hw11.qmd file, include:
- Your interactive chart, with one or two sentences under it describing what it shows.
- A few sentences on what you had to check or correct, and whether the interactivity helped.
5. Experiment: have Claude build a chart in D3
Now try the other route. Ask Claude Code to build a chart entirely in D3 and embed it in your hw11.qmd file. You don’t need to understand the D3 code. The goal is to experience what it looks like, how much more control it gives you, and how well Claude can handle it.
Build it
Use the same data as your plotly chart, or a different data set if you want to try something new. Here is a prompt to get you started (edit it to fit your data and chart):
Build a [line chart / scatterplot / bar chart] of [describe your data] using D3. Put it in a single self-contained file called
d3-chart.htmlin myhw11folder, loading D3 from a CDN. Embed the data directly in the file (don’t load it from a separate file). Add a tooltip on hover, a title that states the main takeaway, labeled axes, and one interaction beyond hover (for example, a dropdown to filter, or a transition when something changes).
Open d3-chart.html in your browser to check it, and keep going back and forth with Claude until you like it. Then embed it in your hw11.qmd file with an iframe:
<iframe src="d3-chart.html" width="100%" height="500" style="border:none;"></iframe>Make sure d3-chart.html is in the same folder as your hw11.qmd file, and that you commit it along with your .qmd when you push. Otherwise the chart won’t show up in your submission.
Check it
A D3 chart is code that Claude wrote from scratch, with none of ggplot’s built-in checks, so verify it just like you would any other output:
- Check the numbers. Hover over a few points and compare the values against your data. Do they match? A chart can look beautiful and be plotting the wrong thing.
- Check the axes. Are they labeled with units? Do they start where they should? Does the chart look right if you resize your browser window?
- Check the claim. Read the title and any annotations. Does the data support exactly what they say?
In your hw11.qmd file, include:
- Your embedded D3 chart.
- A few sentences on how it went: How many back-and-forth rounds did it take? What did Claude get wrong, and how did you notice? What could this chart do that your plotly chart couldn’t, and what was easier in plotly?
6. Reflect
This week, consider writing about when you would reach for ggplot, plotly, or D3 for a project of your own, and what you would need to check before trusting each one.
Reflect on what you’ve learned while going through these readings and exercises. Is there anything that jumped out at you? Anything you found particularly interesting or confusing?
Write at least a paragraph in your hw11.qmd file, and include at least one question. The teaching team will review the questions we get and will try to answer them either in Slack or in class.
Some thoughts you may want to try in your reflection:
- “I used to think ______, now I think ______ 🤔”
- Discuss some of the key insights or things you found interesting in the readings or recent class periods.
- Connect the course content to your own work or project you’re working on.
7. Submit
To submit your assignment, follow these instructions:
- Render your .qmd file by either clicking the “Preview” button in Positron or running
quarto renderin the terminal. - Open the rendered html file and make sure it looks good! Is all the formatting as you expected?
- Commit and push your work using GitHub Desktop: look at the diff, write a short commit message, click Commit, then Push.
Your work isn’t submitted until you’ve pushed it. Committing only saves the change on your own computer – go look at your repo on GitHub.com and confirm your work is actually there before you call this done.