filmov
tv
R Tutorial: ggplot2 layers
Показать описание
---
Now that we have some idea about the different grammatical elements of graphics, let's see how this works in practice.
The grammar of the graphic is implemented in R using the ggplot2 package.
There are two key functions that ggplot2 serves.
First, we construct plots by layering grammatical elements on top of each other.
Second, we use aesthetic mappings to bridge the link between data and it's visual interpretation.
We are going to go through each grammatical element in depth in this and the next course. Here I'll introduce a data set that will be used throughout the videos and we'll go over some simple examples.
The bottom layer is the data element. Obviously, we need some data to plot. I'm going to use several different data sets in the course videos,
One of which is the classic iris data set collected by Edgar Anderson in the 1930s and thereafter popularized by Ronald Fisher.
The data set contains information on three iris species, setosa, versicolor, and virginica.
Four measurements were taken from each plant - the petal length and width and the sepal length and width. You're probably familiar with petals, they're the colorful part of a flower. Sepals are the outer leaves of the flower, they are typically green, but in this case, they're also colorful. There are 50 specimens of each species.
The data is stored in an object called iris, there are five variables: the species and one for each of the properties which were measured.
In this case, we are going to make a scatter plot so we're going to map Sepal-dot-Length onto the X aesthetic and Sepal-dot-Width onto the Y aesthetic.
The next element is the geometry element. This allows us to choose how the plot will look.
After we've established our three essential layers, we have enough instructions to make a basic scatter plot. It's pretty rough, so to get a more meaningful and cleaner visualization, we'll have to use the other layers.
The next layer we'll look at is the theme's element. It controls all the non-data ink on our plot.
Which allows us to get a nice looking, meaningful and publication-quality plot directly in R.
We'll discuss the remaining grammatical elements in the next course.
For now, let's begin by exploring these concepts in the exercises.
#DataCamp #RTutorial #DataVisualizationwithggplot2 #ggplot2