在R表达式中组合矢量变量以绘制图文本 [英] Combining vector variables in R expression for plot text
问题描述
我正在尝试在R图中创建一个文本层,其中包含从变量派生的普通文本和上标文本.
I am trying to create a text layer in an R plot containing normal and superscript text that derives from variables.
到目前为止,我有这个:
So far I have this:
first = c("one", "two", "three")
second = c(1, 2, 3)
plot(1:3, 3:1)
text(1:3, 3:1, labels=first)
它现在的工作方式,在绘图上显示一个,两个等.我希望它显示一个 1 ,两个 2 ,等等.
The way it works now, it shows one, two, etc on the plot. I want it to show one1, two2, etc.
我猜应该是expression
,paste
,bquote
以及其他功能的某种组合.我只是无法获取它来将数据读取为向量并制作适当的上标.
I guess it should be some combination of expression
, paste
, bquote
and maybe another function. I just can't get it to get it to read the data as vectors and make the proper superscript.
我在这个网站上看到了一些问题,例如:
I've seen some questions on this site, for example:
- Combining paste() and expression() functions in plot labels
- Use expression with a variable r
- Including variables in expression call in R
他们都没有完全回答我的问题.
None of them fully answer my question.
推荐答案
也许您可以尝试
plot(1:3, 3:1)
text(1:3, (3:1)-0.03, labels= mapply(function(x,y)
as.expression(bquote(.(x)^.(y))), first, second))
这篇关于在R表达式中组合矢量变量以绘制图文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!