如何在ggplot中的geom_text标签中键入下标

时间:2019-03-20 14:41:34

标签: r ggplot2 subscript geom-text

我绘制了时间序列数据,并按时间点分开,这些时间点想用下标标记。下面是我用来生成图形和时间点标签的代码。我想将-1、3和6下标。预先感谢!

timepoints=data.frame(date=as_datetime(c("2016-08-15" ,"2016-11-22", 
"2017-02-25")), timepoint=c("T-1", "T3", "T6"))

TimeseriespH = ggplot(FinalSeaphox, aes(x=DTTM)) +
geom_line(aes(y=MpH, color = "Outer Bay", group = grp), size = 0.5) +
geom_line(aes(y=CpH, color = "Inner Bay", group = grp), size = 0.5) +
scale_x_datetime(labels = date_format("%b '%y"), date_breaks = "1 
month", limits = as_datetime(c("2016-07-01","2017-04-19"))) +
labs(x = "", y = "pH") +
scale_y_continuous(limits = c(7.4,8.2)) +
geom_vline(xintercept = as_datetime("2016-12-01"), linetype = 2, color 
= "black") +
geom_vline(xintercept = as_datetime("2016-08-26"), linetype = 2, color 
= "black") +
geom_vline(xintercept = as_datetime("2017-03-06"), linetype = 2, color 
= "black") +
geom_text(data=timepoints, mapping=aes(x=date, y=c(8.18, 8.18, 8.18), 
label=timepoint), size=5, vjust=-0.4, hjust=0, inherit.aes = FALSE, 
color = "black")  

1 个答案:

答案 0 :(得分:0)

对于下标,您需要将其括在方括号之间:

long long

然后在timepoint = c("T[-1]", "T[3]", "T[6]") 中使用parse = TRUE

geom_text

enter image description here