This repository contains the materials for D-Lab’s R Data Visualization workshop. Prior experience with R Fundamentals is assumed.
Check D-Lab’s Learning Pathways to figure out which of our workshops to take!
In this workshop, we provide an introduction to data visualization in R. First, we’ll cover some basics of visualization theory. Then, we’ll explore how to plot data in R using base R functions as well as ggplot2
. We aim to cover the following types of plots:
We will also explore the basic grammar of graphics, including the aesthetics and geometry layers, adding statistics, transforming scales, and coloring or paneling by groups. Throughout the workshop, we’ll discuss the plot types best suited for particular types of data.
Basic familiarity with R is assumed. If you are not familiar with material in R Fundamentals, we recommend attending that workshop first.
We will use RStudio to go through the workshop materials, which requires installation of both the R language and the RStudio software. Complete the following steps:
git
, you can instead clone this repository by opening a terminal and entering git clone git@github.com:dlab-berkeley/R-Data-Visualization.git
.Now that you have all the required software and materials, you need to run the code:
Launch the RStudio software.
Use the file navigator to find the R-Data-Visualization
folder that you downloaded from Github.
Double click on the R-Data-Visualization.Rproj
file, and click “yes” when RStudio asks you to confirm whether you want to open up the project.
Open up the R-Data-Visualization.Rmd
file, located in the lessons
folder.
If you do not have the cowplot
, dplyr
, ggplot2
, and here
packages installed, be sure to install them using the install.packages()
function in the first code block of the R-Data-Visualization.Rmd
file.
Run a chunk of code by clicking the green “play” button in the upper right hand corner of each code chunk. Alternatively, place your cursor on a given line and press “Command + Enter” (Mac) or “Control + Enter” (PC) to run an individual line of code.
The file R-Data-Visualization-Challenges.Rmd
contains space for you to work on five challenge problems. The file R-Data-Visualization-Challenges-Solutions.Rmd
contains the solutions to these challenges.
If you do not have R installed and the materials loaded on your workshop by the time it starts, we strongly recommend using the UC Berkeley Datahub to run the materials for these lessons. You can access the DataHub by clicking this link.
The DataHub downloads this repository, along with any necessary packages, and allows you to run the materials in an RStudio instance on UC Berkeley’s servers. No installation is necessary from your end - you only need an internet browser and a CalNet ID to log in. By using the DataHub, you can save your work and come back to it at any time. When you want to return to your saved work, just go straight to DataHub, sign in, and you click on the R-Data-Visualization
folder.
Check out the following resources to learn more about data visualization and R:
D-Lab works with Berkeley faculty, research staff, and students to advance data-intensive social science and humanities research. Our goal at D-Lab is to provide practical training, staff support, resources, and space to enable you to use R for your own research applications. Our services cater to all skill levels and no programming, statistical, or computer science backgrounds are necessary. We offer these services in the form of workshops, one-to-one consulting, and working groups that cover a variety of research topics, digital tools, and programming languages.
Visit the D-Lab homepage to learn more about us. You can view our calendar for upcoming events, learn about how to utilize our consulting and data services, and check out upcoming workshops.
Here are other R workshops offered by the D-Lab:
Thanks to Software Carpentry, Chris Paciorek, Rochelle Terman, and the R-bootcamp for inspiration.