customizing ggplot2
2025-08-09
scale_x_continuous() scale_y_date() scale_x_log10()
scale_color_hue() scale_fill_brewer() scale_shape_manual()

scale_color_distiller() and scale_color_viridis_c(). Check the help pages for different palette options.gender. Try scale_color_brewer().scale_color_manual(). Use values = c("#E69F00", "#56B4E9") in the function call.name argument in whatever scale function you’re using.Non-data ink (text, background, etc)
Pre-specified themes: theme_gray() (default), theme_minimal(), theme_light(), etc.
theme()
mtcars |>
ggplot(aes(hp, mpg, color = factor(cyl))) +
geom_point(size = 3) +
scale_x_log10() +
scale_colour_brewer(name = "Cylinders", palette = "Set2") +
theme_minimal() +
theme(
axis.text = element_text(size = 16),
legend.text = element_text(size = 8, face = "bold"),
legend.direction = "horizontal"
)
| element | draws |
|---|---|
element_blank() |
nothing (remove element) |
element_line() |
lines |
element_rect() |
borders and backgrounds |
element_text() |
text |
theme() to change the legend to the bottom with legend.position = "bottom".axis.ticks argument to element_blank()element_text(). Check the help page if you don’t know what option to change.
?rnorm, ?Distributions
diamonds data set from ggplot2. How many rows does it have?carat vs. price. How’s it look?geom_point() with 2d bins.ggtitle()labs(title = "My Awesome Plot")xlab(), ylab()labs(x = "X Label", y = "Y Label")scale_*() functionslabs(color = "Wow, labs does everything", fill = "Yup")theme(legend.position = "none")hip and pounds for weight). You can use either labs() or xlab() and ylab()scale_linetype() and set the name argument to “Sex”.
ggsave()
ggsave()