Mapping data to graphics
Part 1: Data visualization with ggplot2
For the first part of today’s lesson, you need to work through RStudio’s introductory primers for ggplot2. You’ll do these in your browser and type code and see results there.
It seems like there are a lot, but they’re short and go fairly quickly (especially as you get the hang of the
ggplot() syntax). Complete these:
Part 2: Reshaping data with tidyr
For the last part of today’s lesson, you’ll work through just one RStudio primer to learn how to use the tidyr package to reshape data from wide to long and back to wide.
- Tidy Your Data
Recent versions of tidyr have renamed these core functions:
gather() is now
spread() is now
pivot_wider(). The syntax for these
pivot_*() functions is slightly different from what it was in
spread(), so you can’t just replace the names. Fortunately, both
spread() still work and won’t go away for a while, so you can still use them as you learn about reshaping and tidying data. It would be worth learning how the newer
pivot_*() functions work, eventually, though (see here for examples).