如何在绘图点标签的文本中包含下标

时间:2013-03-21 06:23:23

标签: r text plot subscript

嗨,我是R的新手,所以如果这是一个非常基本的问题,我道歉。 我正在尝试将文本添加到x轴上第11点的绘图中,并在y轴上指向900,将{0}作为下标读取t0= -4.0280t0 <- -4.0280的位置  为此,我尝试过:

text(11,900,paste("t[0]=",t0),cex=0.8) 
# which gives 
't[0]= -4.0280'

text(11,900,expression(paste("t[0]=",t0)),cex=0.8) 
# which gives 
't[0]=t0'

# the closest I've gotten is:    
text(11,900,expression(paste(t[0]==t0)),cex=0.8)

将使用下标但返回t0而不是我的值-4.0280。

有人能告诉我哪里出错了吗?

干杯。

2 个答案:

答案 0 :(得分:5)

您可以将expression替换为substitutepaste不需要list(t0 = t0)。参数substitute告诉t0将字符串t0替换为对象plot(1,1) t0 <- 1.3 text(1, 0.8, substitute(t[0]==t0, list(t0 = t0)), cex = 0.8) 的值:

{{1}}

enter image description here

答案 1 :(得分:3)

substitutebquote相比略短于<{1}}:

plot(1,1)
t0 <- -4.0280
text(1, 0.8, bquote("t"[0] ~ "=" ~ .(t0)))

如果你想在那里使用paste

text(1, 0.8, (bquote("t"[0]~.(paste0('=',t0)))))

enter image description here

以前出现过这种Q:

Using subscript and variable values at the same time in Axis titles in R

Concatenate strings and expressions in a plot's title