Reputation: 823
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)
The way it works now, it shows one, two, etc on the plot. I want it to show one1, two2, etc.
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:
None of them fully answer my question.
Upvotes: 2
Views: 1472
Reputation: 887048
May be you can try
plot(1:3, 3:1)
text(1:3, (3:1)-0.03, labels= mapply(function(x,y)
as.expression(bquote(.(x)^.(y))), first, second))
Upvotes: 5