[R] package grid: mirror grob objects along an axis

Thomas Zumbrunn t.zumbrunn at unibas.ch
Sun Jun 3 22:22:27 CEST 2012


My question was answered off list by Paul Murrell, author of 'grid'. Here's am 
excerpt of our email exchange for the records of R-help.

======== Paul Murrell ========

In some special cases, you would be able to "flip" shapes.  If the 
coordinates of the shapes are given in "native" coordinates, then you 
could reverse the scales on the viewport that you are drawing in.

However, there is no general "flip" operation in 'grid'.  Especially not 
with respect to text.  Text is always left-to-right and sized using 
absolute units (points [modulo cex multipliers]).

If you really desperately needed to do something like this, a last 
resort might be to draw the required "scene" in hi-res raster format. 
You could then easily flip the raster and draw that.

======== Thomas Zumbrunn ========

I was actually asking the question primarily because I wanted to flip text 
grobs...

> If you really desperately needed to do something like this, a last
> resort might be to draw the required "scene" in hi-res raster format.
> You could then easily flip the raster and draw that.

That's exactly what I did as a workaround, but I was hoping that there is a 
more elegant solution - especially since reading in and drawing hi-res raster 
format images slows down the execution time of my code quite considerably.

What about converting text into paths? Could one do this in R? Then one could 
use your suggested solution of reversing the scales of the viewport.

======== Paul Murrell ========

Interesting idea.  You could do that using the 'grImport'.  Something 
like ...

library(grid)
postscript("test.ps")
grid.text("test")
dev.off()

library(grImport)
PostScriptTrace("test.ps", "test.xml")
test <- readPicture("test.xml")
# To check the scales on the picture
# test at summary
grid.picture(test,
              yscale=c(4400, 4000),
              xscale=c(2936.84, 3019.76))




On Tuesday 22 May 2012, Thomas Zumbrunn wrote:
> Hi everyone
> 
> I'd like to flip grobs (grid graphical objects) along an axis, e.g. flip
> grobs horizontally or vertically. I couldn't find any hints, neither in
> the documentation nor by searching the web. Does anybody know how to
> achieve this?
> 
> Cheers
> /thomas



More information about the R-help mailing list