Create galaxy-brain-level errorbars like in THAT paper
In July 2022, a now retracted paper appeared in a special issue of a Hindawi journal Advances in Materials Science and Engineering, that contained a bar chart with the letter T pasted above bars, presumably as a substitute for error bars.
I strongly believe that everyone should be able to quickly produce this
genius graphics. That is the only purpose of ggterror, an extension to
R’s ggplot2 package. Unlike the graphics in the original – and this
word is doing a lot of work here – paper, however, this extension
produces actual errorbars.
You can install ggterror from github using the remotes package:
# install.packages("remotes")
remotes::install_github("mivalek/ggterror")The package contains a single function geom_terrorbar() that should be
used in much the same way as ggplot2::geom_errorbar()
library(ggplot2)
library(ggterror)
library(palmerpenguins)
library(dplyr)
palmerpenguins::penguins |>
dplyr::filter(!is.na(body_mass_g)) |>
dplyr::group_by(species) |>
dplyr::summarise(
mean = mean(body_mass_g),
se = sd(body_mass_g) / sqrt(dplyr::n())
) |>
ggplot(aes(x = species, y = mean)) +
geom_terrorbar(aes(ymin = mean - 2 * se,
ymax = mean + 2 * se)) +
geom_point() +
theme_bw()On top of the usual aesthetics you’d pass to ggplot2::geom_errorbar(),
this function takes a few additional arguments that govern the overal
look of the Ts and the
connecting lines:
connect- logical. Whether or not the Ts should be connected with a line.fontface- one ofc("plain", "bold", "italic")size- size of the Ts in pt unitsline_type- type of connecting line whenconnect = TRUEline_width- width of connecting line whenconnect = TRUEline_alpha- alpha for connecting line whenconnect = TRUE. By default,line_alpha = 0.6 * alphaof the Ts
Reproducing the original plot is easy with geom_terrorbar():
library(ggtext)
df <- tibble::tibble(
x = factor(1:5, labels=c("blank", "pink", "lysozyme", "hOGG1", "Endo IV")),
y = c(3.5, .5, 3.4, 3.2, 3),
ymax = y + .2,
ymin = y - .2,
size = 15
)
df |> ggplot(aes(x, y)) +
geom_terrorbar(aes(ymax = ymax, ymin = ymin), connect = FALSE) +
geom_bar(stat = "identity", aes(fill = x), colour="black", width = .65, lwd = .7) +
labs(x = "", y = "Current (<em>μ</em>A)") +
scale_y_continuous(limits = c(0,4.3), expand=c(0,0)) +
theme_classic() +
scale_fill_manual(values=c("#f3c08f", "#f9ee87", "#3eaba8", "#8fc4f1", "#cecece")) +
theme(
panel.background = element_rect(colour = "black", fill = NA, size = .85),
axis.text = element_text(family="serif", size = 15),
axis.title.y = element_markdown(family = "serif", size = 15),
axis.ticks = element_blank()) +
guides(fill = "none")Hope you have fun creating some true classics!


