
The objective of ggrefine is to provide some pretty ggplot2 complete themes, and refine functions to tweak these easily based on the particulars of a plot.
Install from CRAN, or development version from GitHub.
install.packages("ggrefine")
pak::pak("davidhodge931/ggrefine")The themes are built to work with the refine functions - and can be customised easily.
The theme_grey function differs from the other two in
that the panel_grid_colour by default is derived by
applying a multiply blend on the panel_background_fill.
As the theme names are the same as those in ggplot2, it is
recommended to not load the package, but instead refer to each theme as
ggrefine::theme_*.
library(ggplot2)
p_base_light <- mpg |>
ggplot(aes(x = hwy)) +
geom_histogram(
stat = "bin", shape = 21,
colour = blends::multiply("#357BA2FF")
) +
scale_y_continuous(expand = expansion(mult = c(0, 0.05)))
p_base_dark <- mpg |>
ggplot(aes(x = hwy)) +
geom_histogram(
stat = "bin", shape = 21,
colour = blends::screen("#357BA2FF")
) +
scale_y_continuous(expand = expansion(mult = c(0, 0.05)))
p_light <- p_base_light + ggrefine::theme_light() + labs(title = "ggrefine::theme_light")
p_dark <- p_base_dark + ggrefine::theme_dark() + labs(title = "ggrefine::theme_dark")
p_grey <- p_base_light + ggrefine::theme_grey() + labs(title = "ggrefine::theme_grey")
p_oat <- p_base_light + ggrefine::theme_grey(
panel_background_fill = flexoki::flexoki$base["base50"],) +
labs(title = "ggrefine::theme_grey(panel_background_fill = ...)")
patchwork::wrap_plots(
p_light,
p_dark,
p_grey,
p_oat
)
The ggrefine::refine_* functions adjust gridlines and
axis elements based on axis types (x_type and
y_type), which default to "continuous".
set_theme(new = ggrefine::theme_grey())
p_continuous <- mpg |>
ggplot(aes(x = displ, y = hwy)) +
geom_point(shape = 21, colour = blends::multiply("#357BA2FF"))
p_discrete_x <- mpg |>
ggplot(aes(x = drv, y = hwy)) +
geom_jitter(shape = 21, colour = blends::multiply("#357BA2FF"))
p_discrete_y <- mpg |>
ggplot(aes(x = hwy, y = drv)) +
geom_jitter(shape = 21, colour = blends::multiply("#357BA2FF"))
patchwork::wrap_plots(
p_continuous + ggrefine::refine_modern() + labs(title = "ggrefine::refine_modern"),
p_discrete_x + ggrefine::refine_modern(x_type = "discrete"),
p_discrete_y + ggrefine::refine_modern(y_type = "discrete"),
p_continuous + ggrefine::refine_classic() + labs(title = "ggrefine::refine_classic"),
p_discrete_x + ggrefine::refine_classic(x_type = "discrete"),
p_discrete_y + ggrefine::refine_classic(y_type = "discrete"),
p_continuous + ggrefine::refine_fusion() + labs(title = "ggrefine::refine_fusion"),
p_discrete_x + ggrefine::refine_fusion(x_type = "discrete"),
p_discrete_y + ggrefine::refine_fusion(y_type = "discrete"),
p_continuous + ggrefine::refine_void() + labs(title = "ggrefine::refine_void"),
p_discrete_x + ggrefine::refine_void(x_type = "discrete"),
p_discrete_y + ggrefine::refine_void(y_type = "discrete"),
p_continuous + ggrefine::refine_none() + labs(title = "ggrefine::refine_none"),
p_discrete_x + ggrefine::refine_none(x_type = "discrete"),
p_discrete_y + ggrefine::refine_none(y_type = "discrete"),
ncol = 3
)