showtext icon indicating copy to clipboard operation
showtext copied to clipboard

Provide a grid grob

Open hadley opened this issue 9 years ago • 3 comments

This would be useful for people using grid graphics (e.g. ggplot2) so that you don't need to mess text rendering globally.

hadley avatar Jun 16 '15 20:06 hadley

Hi Hadley, Could you explain a little bit more about this issue? I believe showtext is only in the device level, in charge of rendering text. Grob is more like a description of text, so it stays in the R level and will not be affected by showtext.

yixuan avatar Jun 16 '15 23:06 yixuan

Currently showtext has global effect - it modifies all text rendering. But it would nice to be able to have local effect, so you could selectively use showTextGrob(). The behaviour would be identical, just the scope would be different.

hadley avatar Jun 17 '15 11:06 hadley

OK, now I understand the problem. For base graphics, users can call showtext.begin() and showtext.end() to control the text rendering scope, but for grid graphics, since all graphics components are stored as an R object and then sent to graphics device in a batch, users cannot inject code in between plotting actions. There may be some difficulties to fix this issue, since the current showtext works in the graphics device level, while grob lies in the graphics system level. Theoretically devices cannot see the outer world, for example it cannot tell whether one plotting action (such as drawing a circle) is from a base plot or a grid plot. It is only in charge of the rendering part. I'm not so familiar with the grid system, so I have a few questions here: If I define a grob called showTextGrob(), can I customize how it will be plotted in the R level? If this is possible, one simple solution is to insert a showtext.begin() call inside the plotting method of this grob, and call showtext.end() when exitting. If the answer is positive, I will then read some materials about grid system and grob customization.

yixuan avatar Jun 17 '15 13:06 yixuan