Introduction
Themes control the visual appearance of ggplot2 plots. Built-in themes and custom options are available.
Built-in Themes
ggplot(df, aes(x, y)) + geom_point() +
theme_minimal()
# Other themes
theme_bw()
theme_classic()
theme_dark()
theme_light()
theme_void()
Custom Theme Elements
ggplot(df, aes(x, y)) + geom_point() +
theme(
plot.title = element_text(hjust = 0.5, size = 16),
axis.title = element_text(size = 12),
axis.text = element_text(size = 10),
legend.position = "bottom",
panel.background = element_rect(fill = "white")
)
Removing Elements
ggplot(df, aes(x, y)) + geom_point() +
theme(
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank()
)
Color Palettes
# Color palette
scale_fill_brewer(palette = "Set2")
scale_fill_viridis_d()
scale_color_gradient(low = "blue", high = "red")
Summary
Customize themes for professional-looking plots. Use built-in themes for quick styling.