Section 3.7 ggplot2 Visualization Reference
Unlike other chapters, visualization relies on combining multiple components rather than calling single functions. This section serves as a reference for common geometries, aesthetics, and commands used throughout the book.
Subsection 3.7.1 Summary of ggplot Geometries
Below is a list of plot types, their purpose, and the geom command used:
-
Scatterplot - Relationships -
geom_point() -
Bar Chart - Counts -
geom_bar() -
Column Chart - Pre-summarized values -
geom_col() -
Histogram - Distribution -
geom_histogram() -
Density Plot - Distribution -
geom_density() -
Boxplot - Group comparison -
geom_boxplot() -
Line Graph - Time -
geom_line()
Subsection 3.7.2 Summary of other ggplot commands
Below is a list of other commands used to alter plots:
-
Aesthetics:
-
color: Changes the color of the points. -
shape: Changes the shape of the points. -
alpha: Changes the opacity of the point. -
size: Changes the size of the point. -
fill: Controls the interior color of shapes
-
-
labs(): Creates labels, including title, x-axis, and y-axis. -
facet_wrap(): Creates individual plots and puts it into one graphic. -
coord_flip(): Flips the axes without changing the underlying variables. -
theme(): Controls the overall appearance of the plot -
theme_minimal(): Makes the most basic looking plot. -
theme(legend.position = "..."): Dictates where (if at all) the legend appears on the plot. -
geom_text(): Adds text to the data points within the plot. -
geom_hline(): Adds a horizontal reference line. -
geom_vline(): Adds a vertical reference line. -
geom_smooth(): Adds trend lines. -
reorder(): Reorders categorical variables based on the values of another variable.
