1

I tried searching, but this bothers me quite a bit, as it in my opinion should be a simple line of coding. However, i keep getting an error when trying...

Firstly, this code works fine

  scale_linetype_manual("",
                    values=c("pAl"=4,"pAlOH"=3, "pAl7OH17"=6, "pAl13OH34"=2,"pAlOH4"=1,"pAl2OH2"=5),
                    labels = c(expression("Al"^"3+"),
                               expression("Al(OH)"^"2+"),
                               expression("Al7(OH)"[17]^"4+"),
                               expression("Al13(OH)"[34]^"5+"),
                               expression("Al(OH)"[4]^"-"),
                               expression("Al2(OH)"[2]^"4+")))+

I do, however, want some of the numbers after Al to be subscripted too, but when trying

  expression("Al"[2]"(OH)"^"2+") or expression("Al" ~ [2] ~ "(OH)" ~ ^ ~ "2+")

or whatever variant i can come up with, i keep getting an error.

Again, there's probably an easy fix. Sorry for my lack of experience in using R :)

1
  • Maybe i should have added that this is an extension to my ggplot code. I plot concentrations against pH and want a legend explaining the different linetypes. Commented Nov 23, 2017 at 0:41

1 Answer 1

1
library(grid)

e <- c("Al[2]~(OH)^'2+'", 
       "Al[7]~(OH)[17]^'4+'")
grid.newpage()
grid.text(parse(text=e), y=c(0.4,0.6))

enter image description here

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

3 Comments

Thanks, but when is this converted to an expression instead of just pure text? Inside the grid function? I might be dumb right now, but i can't really figure out how to integrate this into my code. Maybe my full code is required to understand it? Using "Al[7]~(OH)[17]^'4+'" in my string just makes nothing subscripted but instead everything is plain text.
I still didn't solve this issue, do you have any ideas?
@Chemistry101 you have not provided a reproducible example

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.