The objective of ggscribe is to provide annotation helper functions for publication-quality ‘ggplot2’ visualisation.
Note:
- Use the secondary axis, subtitle, or axis titles to adjust space.
-
annotate_axis_*functions placed outside the panel requireclip = "off"in the coord space.
Examples
library(ggplot2)
library(ggrefine)
library(ggscribe)
set_theme(
ggrefine::theme_lights() +
theme(
panel.widths = rep(unit(75, "mm"), 2),
panel.heights = rep(unit(50, "mm"), 2)
)
)
mtcars |>
ggplot() +
aes(x = wt, y = mpg, colour = as.factor(gear), fill = as.factor(gear)) +
scale_colour_blend_discrete() +
#reference lines and background
annotate_reference_line(xintercept = 2.4) +
annotate_reference_line(yintercept = 12) +
annotate_panel_shade(
xmin = 4,
xmax = 5,
) +
#geom
geom_point() +
#clip = "off" is generally required for annotate_* functions
coord_cartesian(clip = "off") +
#top axis
scale_x_continuous(
sec.axis = sec_axis_text(
breaks = c(mean(c(4, 5))),
labels = c("Range"),
guide = guide_sec_axis_text(
angle = 90,
)
)
) +
annotate_axis_bracket(
yintercept = I(1),
breaks = c(4, 5),
) +
annotate_axis_text(
yintercept = I(1),
breaks = c(2.4),
labels = c("Threshold"),
) +
#right axis
annotate_axis_text(
xintercept = I(1),
breaks = 12,
labels = "Threshold",
) +
#bottom axis
annotate_axis_ticks(
yintercept = I(0),
breaks = 3.8,
length = rel(-5),
) +
annotate_axis_text(
yintercept = I(0),
breaks = 3.8,
labels = "Threshold",
length = rel(-5),
) +
labs(x = "\nWeight") +
#annotations fit plot
theme(plot.background = element_rect(colour = "grey92"))
Installation
Install from CRAN, or the development version from GitHub.
install.packages("ggscribe")
pak::pak("davidhodge931/ggscribe")