R Tutorial: Data Visualization in R

Ron Pearson introduces data visualization in R, explaining the difference between exploratory plots that show detail and explanatory plots that highlight findings. He surveys four graphics systems—Base Graphics, Grid Graphics, Lattice, and ggplot2—with examples using ChickWeight and Cars93 datasets.
Chapters
Hi, I'm Ron Pearson and I will be your instructor for this course. I've been using R or its commercial near equivalent S for a long time to analyze data in many different fields. When we're faced with a new data set, especially a large one, one of the first questions we need to ask is what's in it? Because our ability to see patterns is very highly developed, an effective way to approach this question is through graphical data displ or data visualizations. It is important to distinguish between exploratory visualizations designed to help us see what's in a data set and explanatory visualizations designed to help others see what we have found. As we will see, R provides many useful tools for creating data visualizations of both types. The key to a useful exploratory visualization is keeping all of the potentially relevant details. The objectives is to help you see what is in the data, and the key practical question is how much detail can you see and interpret? The plot array on this slide provides a representative example. It summarizes the relationships between the four variables in the chick weight data frame in Rs built in data sets package. From these plots we can see, for example, that weight varies systematically with time and that the chicks were assigned to four different diets. Explanatory data visualizations show others what you have found in the data. This means you must make editorial decisions. What features do you want to highlight for emphasis? What features are distracting or confusing and should be eliminated? Here is an explanatory plot constructed from the cars 93 data frame in the MAS package, emphasizing that highway mileage always exceed city mileage using techniques like reference lines and sunflower plots that you will learn about in this course. To visualize data, R supports four graphics systems. Base Graphics is the easiest to learn and is the focus of this course. Grid Graphics provides a powerful set of modules for building other tools. Lattice Graphics is a general purpose graphics system that, based on Grid Graphics and ggplot2, implements the grammar of graphics in R and is also based on Grid graphics. This first example uses the Base Graphics plot function to generate a simple scatter plot of calories versus sugars from the US serial data frame in the MASS package. The second example uses Grid Graphics to create essentially the same plot. Grid Graphics offers much greater power and flexibility than Base graphics, but this comes at the price of a steeper learning curve and greater effort required to create simple plots like this one. This is the reason that the Grid Graphics system is mainly used by R package developers to create special visualizations or other graphics systems like the Lattice and ggplot two packages. This third example illustrates the use of the Lattice package, which makes it easy to construct conditional scatter plots like the one shown here. These plots allow us to see how the relationship between the variables MPG city and horsepower from the cars 93 data frame change for different values of the cylinders variable. Finally, this fourth example gives a simple illustration of how the ggplot2 package can be used to build up more complex data displays by adding new details to a simple plot or modifying those details. Now it's your turn. The next few exercises will give you a chance to use the plot function for yourself and begin learning what you can do with base graphics in R.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







