2

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.

1 Answer 1

5

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))

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I was hoping to do without any custom functions, but it definitely works.
@Michael Do you mean without bquote, expression, paste etc?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.