向 R 中的字符向量添加下标

问题描述 投票:0回答:0

我看到很多将下标和上标放入绘图标签的示例,但我很好奇如何将下标添加到最终可用于绘图的字符向量。

示例数据和绘图:

 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))

如何让1和2成为剧情的下标?

r subscript
© www.soinside.com 2019 - 2024. All rights reserved.