R Tutorial: ggplot2 layers
Key Takeaways
The video tutorial covers the basics of ggplot2 layers, including data, aesthetics, geometry, and themes, using the iris dataset as an example. It introduces the grammar of graphics and how ggplot2 implements it, with a focus on layering grammatical elements and aesthetic mappings.
Full Transcript
now that we have some idea about the different grammatical elements of graphics let's see how this works in practice the grammar of graphics is implemented in art 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 its visual interpretation we are going to go through each grammatical element in depth in this and the next course here I'll introduce the data set which 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 which is a classic iris dataset 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 staple length and width you're probably familiar with petals there at the colorful part of a flower sepals are the outer leaves of the flower they are typically green but in this case they're all so colorful there are 50 specimens in 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 the next layer will add is the aesthetics element which tells us which scales we should map our data on to this is where the second main component of the grammar of graphics comes into play on top of layering the grammatical elements it's here that we establish our aesthetic mappings in this case we are going to make a scatter plot so we're going to map sepal dot lengths onto the X aesthetic and sepal dot widths 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 it more meaningful and cleaner visualization we'll have to use the other layers the next layer we'll look at is the themes 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 our we'll discuss the remaining grammatical elements in the next course for now let's begin by exploring these Const
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/introduction-to-data-visualization-with-ggplot2 at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
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 la
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: Data Literacy
View skill →
🎓
Tutor Explanation
DeepCamp AI