[英]How to include subscript in text for plot point labels
嗨,我是R的新手,所以如果這是一個非常基本的問題,我道歉。 我正在嘗試在x軸上的點11處添加文本到y軸上的點900,其將讀取t0= -4.0280
,其中0作為下標。 哪里t0 <- -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。
誰能告訴我哪里出了問題?
干杯。
您可以替換expression
與substitute
。 沒有必要paste
。 參數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)
比bquote
略短於substitute
:
plot(1,1)
t0 <- -4.0280
text(1, 0.8, bquote("t"[0] ~ "=" ~ .(t0)))
如果您想在那里使用paste
:
text(1, 0.8, (bquote("t"[0]~.(paste0('=',t0)))))
之前出現過這種Q:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.