Session 1: Data visualization
This week, we will explore how to turn data into clear, compelling visuals using ggplot2 in R (part of the tidyverse). You will learn the core ideas behind the grammar of graphics, how to build plots step by step, and how to customize them to tell better data stories.
We will dive into R training by reading the first section of R for Data Science (Second Edition), exploring interactive tutorials that follow along with the readings, and completing the exercises from the chapter.
The following order of activities is recommended:
Step 1: Book chapter reading. Read chapter 1 in the R for Data Science book. At this stage, you do not need to complete any of the exercises in the book — simply skip them for now and continue reading to the end of the chapter. We will return to the book exercises a bit later (see below).
Step 2: Interactive tutorial. Go through the r4ds.tutorials: 01-data-visualization interactive tutorial. You can find more information about the tutorials and how to install the package (if you haven’t already) here. In the upper-left pane of the RStudio IDE, you will find a tab named Tutorials. Click this tab and scroll down until you locate the correct tutorial, then click Start Tutorial. RStudio will load for a moment and then replace the list of tutorials with the actual tutorial. You should see a window with the text Data Visualization at the top.
The tutorials are designed to give you hands-on experience working with R code. Most of them follow the corresponding chapters from the R for Data Science book, and the majority of exercises are interactive versions of code examples from the text. Some of the key explanatory passages from the chapters are also included.
Below are some useful pieces of information to help you navigate the tutorials.
Above the tutorial window to the left, you will see three icons; a house a window and arrow and a stop sign. Clicking the house icon will take you back to the list of tutorials without quitting the one you are currently viewing. The window-and-arrow icon opens the tutorial in a new window. We strongly recommend doing this and making the window wide enough to display the table of contents on the left. This will make navigating the tutorial easier, and some of the output will also display better when you have more screen space. The stop sign icon quits the tutorial. One useful thing to know is that whenever you quit a tutorial and open it again, it will return you to where you left off, and your previous work will be saved.
The first thing the tutorial will ask you to do is fill out some information. Please provide your name and email (you can ignore the ID request). Note that there is a small bug in the tutorial: after you enter your name and email and click Submit Answer, the button will change color and display Try Again. This is fine — your answer has been submitted successfully, and you can safely disregard this message.
Each exercise asks you to enter some code into an interactive code window. These windows function like mini R apps that run the code you enter and display any resulting output. Once you’ve finished writing your code, click the Run Code button to execute it. When you do this, a check mark will appear next to the exercise number. Note that this check mark does not indicate a correct answer — only that an answer has been submitted. You can change your response as many times as you like; only the most recent version (after clicking Run Code) will be saved.
At the top of each code window, you will find a Start Over button and a Hint button. These buttons clear all code and display helpful hints, respectively.
Sometimes the tutorial exercises will ask you to do something outside of the tutorial window. Exercise 3 this week is an example of this. In this case, you will be asked to run some code in the Console (in the lower left part of the RStudio IDE), copy text from the Help tab (lower right part of the IDE) and paste it into a dedicated text box in the tutorial window.
The tutorials occasionally diverge from the corresponding book chapters. For instance, Exercise 8 introduces the pipe (
|>) operator, which does not appear in the book until Chapter 3.At the end of the tutorial, once you have completed all the exercises, you will be asked to indicate how long it took you to complete the tutorial. The same “Try Again” bug mentioned earlier occurs here again and can be disregarded.
The last thing you need to do before exiting the tutorial is download an HTML file containing your answers.
Step 3: Book chapter exercises. Now revisit the book chapter. By this point, you should be quite familiar with this week’s R coding topics and well equipped to complete the book exercises. There are 10 + 4 + 7 + 2 = 23 exercises in total in chapter 1. Store you answers in an R script and call this file Session_1.R. In cases where an exercise asks you to provide an answer that is not code-based (for example, a question like “What does the bins argument in geom_histogram() do?”), you should still record your response directly in the script file. To do this, add your answer as a comment — that is, on a line beginning with #. This ensures that all your work, both code and written explanations, is saved in one place and easy to review later.
Step 3.5: One-on-one meetings. If what is described above makes it sound like you will be learning the material all on your own, don’t worry. You will have a one-on-one mentoring meeting with Hasse to go over your work when you have completed about the first half of the book chapter exercises. These meetings are mandatory for fellows but optional for graduate students.
Meeting on Monday works best — it gives you some time to work on the exercises beforehand, and still finish the rest afterward, before we meet again as a group on Wednesday to continue discussing the materials. Try to schedule the meeting for Monday morning, since Hasse is based in Sweden and earlier times work best with the time difference. If Monday doesn’t work, Friday (the week before) or Tuesday are acceptable alternatives.
To schedule your meeting, just send Hasse a message on Slack with some times when you are available. The meeting is a chance for you to get help with the exercises, ask questions, and a chance for you and Hasse to get to know each other better. We’ll aim for about 30 minutes, but if you need more help/time, you can request a longer meeting.
Step 4: Send Answers. Send Hasse both the HTML file containing the tutorial exercise answers and the R script file with the book chapter exercise answers via Slack no later than the end of the day on Tuesday.
Step 5: Wednesday group discussion. We’ll meet as a group every Wednesday to discuss what you’ve been learning and reflect on your progress.