Concept: Leland Wilkinson
Implementation: Hadley Wickham
Data
Aesthetics
Geometrics
Facets
Scales
Statistics
Coordinates
Themes
A data frame or tibble containing data for the plot.
How variables in the data are mapped to visual properties (aesthetics
) of geometries (geoms
)
The visual elements used to plot data
Plotting small multiples (Partition the data into smaller “sub plots”, or panels)
cales control the mapping between data values and aesthetics like color, size, and shape. You can customize scales using functions like scale_x_continuous(), scale_fill_manual(), etc., to adjust the appearance of the plot.
Visualize statistical measures
Controls coordinate system
Themes control non-data elements, including elements like background color, grid lines, axis labels, and titles.
ggplot(data=penguins, aes(x=flipper_length_mm, y=body_mass_g, col= species)) +
geom_point() +
facet_grid(species ~ island) +
scale_color_brewer(palette = "Dark2") +
stat_summary(
geom = "point",
fun.y = "mean",
col = "black",
size = 3,
shape = 24,
fill = "red",
alpha = 0.5,
) + coord_cartesian() +
theme(title = element_text("Penguin flipper length vs body mass"),
axis.title.x = element_text("Flipper length (mm)"),
axis.title.y = element_text("Body mass (g)"),
legend.position = "bottom")
ggplot(data=penguins, aes(x=flipper_length_mm, y=body_mass_g, col= species)) +
geom_point() +
facet_grid(species ~ island) +
scale_color_brewer(palette = "Dark2") +
stat_summary(
geom = "point",
fun.y = "mean",
col = "black",
size = 3,
shape = 24,
fill = "red",
alpha = 0.5,
) + coord_cartesian() + theme_bw() +
theme(title = element_text("Penguin flipper length vs body mass"),
axis.title.x = element_text("Flipper length (mm)"),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
axis.title.y = element_text("Body mass (g)"),
legend.position = "bottom")
ggplot(data=penguins, aes(x=flipper_length_mm, y=body_mass_g, col= species)) +
geom_point() +
facet_grid(species ~ island) +
scale_color_brewer(palette = "Dark2") +
stat_summary(
geom = "point",
fun.y = "mean",
col = "black",
size = 3,
shape = 24,
fill = "red",
alpha = 0.5,
) + coord_cartesian() +
theme(title = element_text("Penguin flipper length vs body mass"),
axis.title.x = element_text("Flipper length (mm)"),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
axis.title.y = element_text("Body mass (g)"),
legend.position = "bottom") + theme_bw()
ggplot(data=penguins, aes(x=flipper_length_mm, y=body_mass_g, col= species)) +
geom_point() +
facet_grid(species ~ island) +
scale_color_brewer(palette = "Dark2") +
stat_summary(
geom = "point",
fun.y = "mean",
col = "black",
size = 3,
shape = 24,
fill = "red",
alpha = 0.5,
) + coord_cartesian() +
theme(title = element_text("Penguin flipper length vs body mass"),
axis.title.x = element_text("Flipper length (mm)"),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
axis.title.y = element_text("Body mass (g)"),
legend.position = "bottom") + theme_dark()
ggplot(data=penguins, aes(x=flipper_length_mm, y=body_mass_g, col= species)) +
geom_point() +
facet_grid(species ~ island) +
scale_color_brewer(palette = "Dark2") +
stat_summary(
geom = "point",
fun.y = "mean",
col = "black",
size = 3,
shape = 24,
fill = "red",
alpha = 0.5,
) + coord_cartesian() +
labs(tile = "Penguin flipper length vs body mass",
x = "Flipper length (mm)",
y = "Body mass (g)") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), legend.position = "bottom") + theme_dark()