Data visualization and transformation
With ggplot2, you can create a wide variety of plots layer-by-layer:
Foundation of the plot that gives you the canvas on which you can “paint” your data:
Characteristics of plotting characters that can be mapped to a specific variable in the data, e.g.:
color
shape
size
alpha
(transparency)The color
aesthetic mapped to species
:
The shape
aesthetic mapped to island
:
The color
and shape
aesthetics mapped to species
:
The size
aesthetic mapped to body_mass_g
:
The alpha
aesthetic mapped to flipper_length_mm
:
Determine the size, alpha, etc. of points based on the values of a variable in the data – goes into aes()
:
Determine the size, alpha, etc. of points not based on the values of a variable in the data – goes into geom_*()
:
Visual representations of data points:
geom_*()
functions are used to add geoms to a plotgeom_point()
geom_smooth()
and many more soon…
more on these later…
Control the non-data elements of the plot:
theme_*()
functionstheme()
functiontheme_dark()
theme()
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, color = species)) +
geom_point() +
theme(legend.position = "bottom")
and many more throughout the course…