gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:13:21 30 4
gpt4 key购买 nike

我有时间序列数据绘制并由我想用下标标记的时间点分隔。下面是我用来生成图形和时间点标签的代码。我希望 -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")

最佳答案

对于下标,您需要用括号括起来:

timepoint = c("T[-1]", "T[3]", "T[6]")

然后使用 parse = TRUEgeom_text :
library(ggplot2)
library(lubridate)

timepoints=data.frame(
date = as_datetime(c("2016-08-15" ,"2016-11-22", "2017-02-25")),
Y = c(8, 8.1, 8)
timepoint = c("T[-1]", "T[3]", "T[6]")
)
ggplot(timepoints) +
geom_point(aes(x = date, y=Y), size = 3) +
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", parse = TRUE)

enter image description here

关于r - 如何在ggplot的geom_text标签中键入下标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55263468/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com