4

I am having trouble keeping the superscript next to its symbol when using multiple lines of text in a base R plot. Consider the following example:

plot(c(0,1), c(0,1), axes=F, xlab="", ylab="", type='n')
x1 <- expression(paste("(1) here is some text s" ^-1))
text(0.5, 0.25, x1)

x2 <- expression(paste("(2) here is some text\n s" ^-1))
text(0.5, 0.5, x2)

enter image description here

Case "1" is fine, but in case "2" a lot of white space is added

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • 2
    Seems to differ depending on how the paste is constructed - `text(0.5,0.5,expression(paste("some text\n", "what")))` vs `text(0.5,0.2,expression(paste("some text\n what")))` for instance. It is okay when all in one string but gets interpreted differently when separated. Even though both `paste` strings give the same result when evaluated normally. – thelatemail May 30 '18 at 23:02
  • 1
    Looks like line breaks in `expression`s are difficult at best to get to work - https://stackoverflow.com/questions/18237134/line-break-in-expression – thelatemail May 31 '18 at 00:44

0 Answers0