[R] Two == expressions in bquote

Larry Hotchkiss larryh at udel.edu
Mon Jan 25 21:00:07 CET 2010


Hi,

I want to put text on a plot containing something like: a = b^2 = <squared numeric value of b> using bquote.

Example:

  mu = 5
  plot(1:10,1:10)
  text(2,8, bquote(delta == mu^2))            # This works
  text(2.5,8, bquote(phantom(0) == .(mu^2)))  # but is unpredictable

  text(2,8, bquote(delta == mu^2 == .(mu^2))) # This doesn't work

The last text function returns the error:

     Error: unexpected '==' in "  text(2,8, bquote(delta == mu^2 =="

The first two text functions work in this example, using a default graphics window on a 64-bit Windows machine, and either R 2.11.0 development edition for 64-bit Windows or R 9.2.2 on the same machine ((x 86)). 

I don't mind the two statements except that when trying to automate this by using the base x coordinate + epsilon*max(x), for example --

  x <- 1:10
  epsilon=0.05
  text(2+esilon*max(x),8, bquote(phantom(0) == .(mu^2)))

for the x position on the 2nd text function, the position of the additional text is not predictable.

Thanks,

Larry Hotchkiss



More information about the R-help mailing list