I see a lot of examples for getting subscripts and superscripts into plot labels, but I'm curious how to add a subscript to a character vector that can eventually be used for a plot.
Example data and plot:
data.frame(site = LETTERS[1:10],
a1 = c(rep(1, 7), rep(NA, 3)),
a2 = c(rep(NA, 4), rep(2, 6)),
minY = sample(1:9, 10, replace = TRUE),
maxY = sample(10:19, 10, replace = TRUE)) %>%
mutate(label = case_when(is.na(a1) ~ paste(site, a2, sep = ""),
is.na(a2) ~ paste(site, a1, sep = ""),
TRUE ~ paste(site, paste(a1, a2, sep = ","), sep = ""))) %>%
ggplot() +
geom_segment(aes(x = label, xend = label, y = minY, yend = maxY))
How can I made the 1's and 2's into subscripts for the plot?