2024-03-28
What is the theme
of a visualization?
Ready-to-use themes
Text size
Text colour, bold, italics, and more
Legend spacing and positioning
Formatting axis numbers
theme_dark
, theme_gray
, theme_light
From ggthemes
: theme_wsj
, theme_tufte
, theme_fivethirtyeight
, theme_economist
, theme_clean
p1 + theme(axis.text.x = element_text(size=16),
axis.title.y = element_text(size=18),
legend.title = element_text(size=16),
legend.text = element_text(size=18),
plot.title = element_text(size=21),
plot.subtitle = element_text(size=20)) +
labs(x = "Year",
y = "Life Expectancy at birth",
title = "Life expectancy averaged by continent",
subtitle = "From Gapminder.org")
p1 + theme_bw() + theme(legend.position = c(0.03, 0.98),
legend.justification = c(0,1),
legend.direction = "vertical",
legend.background = element_rect(fill = "transparent"),
legend.text = element_text(size = 10, vjust = 0.5),
legend.title = element_blank(),
legend.key.size = unit(0.8, "cm")) +
guides(color = guide_legend(ncol = 3))
tibble(x=10^seq(0,15), y = x*1e-15) |> ggplot(aes(x , y)) + geom_blank() +
scale_x_continuous(trans = "log10", labels = label_number(scale_cut = cut_si("g")),
breaks = c(1e0,1e3,1e6,1e9,1e12,1e15)) +
scale_y_continuous(trans = "log10", labels = label_number(scale_cut = cut_si("m")),
breaks = c(1e-15,1e-12,1e-9,1e-6,1e-3,1e0))
theme(line, rect, text, title, aspect.ratio, axis.title, axis.title.x, axis.title.x.top, axis.title.x.bottom, axis.title.y, axis.title.y.left, axis.title.y.right, axis.text, axis.text.x, axis.text.x.top, axis.text.x.bottom, axis.text.y, axis.text.y.left, axis.text.y.right, axis.ticks, axis.ticks.x, axis.ticks.x.top, axis.ticks.x.bottom, axis.ticks.y, axis.ticks.y.left, axis.ticks.y.right, axis.ticks.length, axis.ticks.length.x, axis.ticks.length.x.top, axis.ticks.length.x.bottom, axis.ticks.length.y, axis.ticks.length.y.left, axis.ticks.length.y.right, axis.line, axis.line.x, axis.line.x.top, axis.line.x.bottom, axis.line.y, axis.line.y.left, axis.line.y.right, legend.background, legend.margin, legend.spacing, legend.spacing.x, legend.spacing.y, legend.key, legend.key.size, legend.key.height, legend.key.width, legend.text, legend.text.align, legend.title, legend.title.align, legend.position, legend.direction, legend.justification, legend.box, legend.box.just, legend.box.margin, legend.box.background, legend.box.spacing, panel.background, panel.border, panel.spacing, panel.spacing.x, panel.spacing.y, panel.grid, panel.grid.major, panel.grid.minor, panel.grid.major.x, panel.grid.major.y, panel.grid.minor.x, panel.grid.minor.y, panel.ontop, plot.background, plot.title, plot.title.position, plot.subtitle, plot.caption, plot.caption.position, plot.tag, plot.tag.position, plot.margin, strip.background, strip.background.x, strip.background.y, strip.clip, strip.placement, strip.text, strip.text.x, strip.text.x.bottom, strip.text.x.top, strip.text.y, strip.text.y.left, strip.text.y.right, strip.switch.pad.grid, strip.switch.pad.wrap)
element_blank()
element_rect( fill = NULL, colour = NULL, linewidth = NULL, linetype = NULL, color = NULL)
element_line( colour = NULL, linewidth = NULL, linetype = NULL, lineend = NULL, color = NULL, arrow = NULL)
element_text( family = NULL, face = NULL, colour = NULL, size = NULL, hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL, color = NULL, margin = NULL)
Chapter on Theme in the ggplot book (currently being revised.)