1

I have four different kinds of graphic, each converted to a grob with apparent success. I am trying to combine them into a single image with grid.arrange(). One of the four -- I would say the simplest of the four -- produces an error, even without the other three.

grid.text(expression(atop("first line", 
                            scriptstyle("second line"))),
            vjust = 0, gp=gpar(fontfamily = "HersheySans"))

Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  Metric information not available for this family/device

This is the traceback()

8: grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, 
       resolveHJust(x$just, x$hjust), resolveVJust(x$just, x$vjust), 
       x$rot, x$check.overlap)
7: drawDetails.text(x, recording = FALSE)
6: drawDetails(x, recording = FALSE)
5: drawGrob(x)
4: recordGraphics(drawGrob(x), list(x = x), getNamespace("grid"))
3: grid.draw.grob(tg)
2: grid.draw(tg)
1: grid.text(expression(atop("first line", scriptstyle("second line"))), 
       vjust = 0, gp = gpar(fontfamily = "HersheySans"))

I get the same error if I remove scriptstyle and vjust from the function, so they aren't the culprits.

I can't even figure out what function the error comes from. grid.Call.graphics isn't exported, but grid:::grid.Call.graphics does not have an error message like that in it's code, and neither do as.graphicsAnnot, resolveHJust, or resolveVJust.

I've hit the wall on this one. Any ideas or suggestions how to resolve this or get around it much appreciated.

All done under Windows 7.

baptiste
  • 75,767
  • 19
  • 198
  • 294
andrewH
  • 2,281
  • 2
  • 22
  • 32

1 Answers1

2

From ?Hershey,

You cannot use mathematical expressions (plotmath) with Hershey fonts.

which means that Hershey fonts are incompatible with anything listed in ?plotmath, such as scriptstyle, atop, and of course expression.

baptiste
  • 75,767
  • 19
  • 198
  • 294
  • Are you referring to my use of the scriptstyle function? That can not be causing this problem because I got the exact same error when I removed scriptstyle. But I suppose it could cause a different problem when I fix this one. I could not find any documentation for non-Hershey fonts in gpar fontfamily specifications. Are there such? – andrewH Nov 05 '16 at 17:43
  • Ah! Thank you. I did not realize That that was not the base R "expression." – andrewH Nov 07 '16 at 21:47