Learn R: Fundamentals of Data Visualization with ggplot2
Learn the basics of how to create visualizations using the popular R package ggplot2.
StartKey Concepts
Review core concepts you need to learn to master this subject
Grammar of Graphics with ggplot2
Geom Aesthetics
ggplot2 Bar Chart
ggplot2 Aesthetics
ggplot2 Labels
ggplot() Initializes a ggplot Object
Grammar of Graphics with ggplot2
Grammar of Graphics with ggplot2
ggplot2 uses the basic units of the “grammar of graphics” to construct data visualizations in a layered approach.
The basic units in the “grammar of graphics” consist of:
- The data or the actual information that is to be visualized.
- The geometries, shortened to “geoms”, which describe the shapes that represent the data. These shapes can be dots on a scatter plot, bar charts on the graph, or a line to plot the data. Data are mapped to geoms.
- The aesthetics, or the visual attributes of the plot, including the scales on the axes, the color, the fill, and other attributes concerning appearance.
Visualizations in ggplot2 begin with a blank canvas, which is just an empty plot with data associated to it. Geoms are “added” as layers to the original canvas, adding representations of the data to the visualization.
In the visual above:
- The first line declares the data that will be used in the plot (
mtcars
) and creates the aesthetic mapping ofwt
tompg
. - The second line creates the data point geom layer.
- The third line creates the smoothed geom layer.
The key is that the aes()
(aesthetic function) on line one maps the data onto each of the two geom layers
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory