ggbreak is a one-function R package for adding a y-axis break symbol to a line chart made using ggplot2. (The function will return an error if any other chart type is supplied.)
The package has been developed to support analysts in ensuring their charts comply with Government Analysis Function data visualisation guidance on breaking or truncating the numerical axis.
Current Analysis Function guidance recommends drawing the break symbol on in Microsoft PowerPoint. Using add_break_symbol()
is a reproducible alternative which you can include in your typical data visualisation workflow.
ggbreak can be installed directly from the UKHSA-Collaboration GitHub page:
# install.packages("devtools")
devtools::install_github("UKHSA-Collaboration/ggbreak")
Let's start by creating a basic line chart using ggplot2.
library(ggplot2)
library(scales)
df <- data.frame(x = 1:20, y = rnorm(20, mean = 12000, sd = 2000))
p <- ggplot(df, aes(x, y)) +
geom_line()
p
Now, let's add a break symbol to the y-axis.
p +
add_break_symbol(p)
add_break_symbol()
can take a range of additional arguments which control the scale of the y-axis and the formatting of the break symbol.
library(afcharts)
plot_break_af <- ggplot(df, aes(x, y)) +
geom_line(colour = af_colour_values[1],
linewidth = 1.2) +
theme_af(ticks = "x") +
labs(x = "Independent variable",
y = NULL,
subtitle = "Dependent variable")
plot_break_af <- plot_break_af +
add_break_symbol(plot_break_af, y_fmt = "comma")
add_break_symbol()
works well when used with the afcharts package.
Authors: Analytics and Data Science Directorate, UK Health Security Agency.
Unless stated otherwise, the codebase is released under MIT License. This covers both the codebase and any sample code in the documentation.
The documentation is Crown copyright and available under the terms of the Open Government 3.0 licence.