Once you have a basic graph, you may want to further alter its appearance. Some common customizations include:
labs()
)scale_fill_manual
)theme()
to the graph, changing its overall appearance (e.g. theme_dark()
, theme_bw()
, theme_classic()
,theme_minimal()
You can also change individual aspects of your them inside of the theme()
call. For specifics of working with theme()
, see the ggplot2 documentation.
To see these customizations in action, start with the scatterplot showing penguin bill length and body mass by island (created above), and add a few lines to change title, color, and labels:
ggplot(data = penguins,
mapping = aes(x = bill_length_mm, y = body_mass_g, color = island)) +
geom_point(alpha = 0.7) +
scale_color_manual(values = c("magenta3", "darkorange", "blue4")) +
labs(x = "Bill length (mm)",
y = "Body mass (g)",
title = "Palmer Penguins",
subtitle = "Examining penguin body mass and bill length") +
theme_bw()
To read more about ggplot2
, see the R for Data Science chapter about data visualization. More extensive documentation can be found on the ggplot2 website.