install.packages('gganimate')
install.packages('magick')Trends
Due: Oct 26 by 11:59pm
Weight: This assignment is worth 1% of your final grade.
Purpose: The purpose of this assignment is to extend the data visualization skill you built in week 6 so that it knows how to handle trends and time series, then use it to make (and animate) a chart of change over time. Along the way, you will learn enough about dates and animation to check whether your agent got the details right.
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 hw8 folder. Open the hw8.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
Trends are all about change over time, which means time is almost always on the x-axis and the chart’s job is to make the shape of that change easy to see. These two chapters cover the main options (points, lines, smoothed lines, and what to do when you have many series at once):
- Wilke: 13 - Visualizing time series
- Wilke: 14 - Visualizing trends
Some examples of visualizations we’ll explore in class:
- The animated line chart: Changes in how couples meet over time
- The heatmap: How common is your birthday?
- The calendar heatmap: ggplot2 time series heatmaps
Optional:
This video by Hans Rosling is a great summary of his larger TED talk on the “gapminder” project he started showing life expectancy and GDP over time. This is an excellent example of using an animated chart to tell a much richer story than a static chart.
Coding techniques
The readings below cover two things that show up in charts of trends: dates & animation. Time series data often arrives with dates stored as text, which means an agent can end up sorting “Apr” before “Jan” or drawing a line straight across a gap in the data without telling you. You need to know enough about how R stores dates (and the lubridate package) to spot when the time axis is wrong. Animation is the other new tool this week: the gganimate package takes a regular ggplot and adds a transition_*() function to make it move, which is how charts like the Rosling video above are made.
- R4DS: 17 - Dates and times - just browse over this, it’s lengthy, but a good reference for dealing with time on the x-axis.
- gganimate: Getting started
- R Graph Gallery: Animation (browse a few examples to see what’s possible)
To render animations, you’ll need two new packages:
3. Extend your skill, then make a chart
In week 6 you built your own data visualization skill (e.g., .claude/skills/my-dataviz/SKILL.md). So far it covers charts like amounts and proportions. This week you will teach it how to handle trends.
Extend your skill
- Open Claude Code in your course repo and ask it to help you add a section on trends and time series to your existing skill, using the readings above as source material (you can give it the URLs). Ask it to extend the skill you already have, not write a new one.
- Read what it wrote. Does the new section capture the guidance from the readings? Some things worth checking for:
- Is time on the x-axis, and is it stored as a date (or number) rather than text?
- When should the chart show points, lines, or a smoothed line, and if it smooths, does it say what the smoothing is doing?
- Does the y-axis need to start at zero, or is it okay to zoom in on the change?
- What should happen with many series at once: directly labeled lines, highlighting one series, or a heatmap instead?
- What should happen when data are missing for some periods?
- Make it yours. Edit the new section (directly, or by asking Claude to) so it reflects your own choices, such as how you like to label lines or when you think an animation is worth it.
Use your skill to make a chart
Find a dataset that has a time variable. Some options:
- The
gapminderdata frame from the gapminder package (the same data as the Rosling video). - The
economicsdata frame that comes with ggplot2. - Data from the Packages section of the “Finding Data” page, or from your project.
Then ask Claude to make a chart of a trend using your skill (invoke it with /your-skill-name).
Check the result against your skill and the readings. In particular, look closely at the time axis: is it stored as a date or a number, and are the periods in order? If there are gaps in the data, does the line jump across them? If the line looks jagged, is that because there’s more than one row per time point (meaning the data should be summarized first)? If something is wrong, fix it, and consider whether your skill should be updated so that it gets it right next time.
Animate it
Now ask Claude to animate your chart with gganimate (for a line chart, transition_reveal() is a good place to start). Watch the result and decide whether the animation actually adds something, or whether the static chart tells the story just as well.
In your hw8.qmd file, include:
- A few sentences on what you added to your skill, and what you changed after Claude drafted it.
- The trend chart you made with your skill, with one or two sentences under it describing what it shows.
- Your animated chart.
- A few sentences on how it went: What did you have to check or correct on the time axis? Did the animation help, and why or why not?
4. Reflect
This week, consider writing about a chart you’ve seen that shows a trend, especially one that made a change look bigger or smaller than it really was.
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 hw8.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.
5. 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.