2

How can i write H2o in the title of a plot?

H2 works:

plot(main=expression("H"[2]),0)

H2O fails:

plot(main=expression("H"[2]"O"),0)

This solution will work only, if i have a space in front " "

plot(main=expression(" "*H[2]*"O"),0)
plannapus
  • 18,529
  • 4
  • 72
  • 94
Jonas Stein
  • 6,826
  • 7
  • 40
  • 72

1 Answers1

6

You were close. This works:

plot(1:10, main = expression(H[2]*O))

The reason for this is that the 2 is a subscript to element H and you want to position element O next to the H. The notation x * y in an expression means juxtapose x with y, i.e. place x and y together. See ?plotmath for more.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453