Skip to content

package grid: mirror grob objects along an axis

5 messages · Rui Barradas, Thomas Zumbrunn, Baptiste Auguie

#
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
#
Hello,

Just flip 'xlim' or 'ylim'. Or both.
Using the iris example in help("grid"), make the following changes:


op <- par(mfcol = c(2,2))  # Two columns, first is the original, second
flipped.

with(iris,

      [... etc ...]
     # row 1, col 2: flip x axis
     plot(Sepal.Length, Sepal.Width, col = as.integer(Species),
          xlim = c(8, 4), ylim = c(2, 4.5), panel.first = grid(),
          main = "with(iris,  plot(...., panel.first = grid(), ..) )")
     # row 2, col 2: flip y axis
     plot(Sepal.Length, Sepal.Width, col = as.integer(Species),
          xlim = c(4, 8), ylim = c(4.5, 2), 
          panel.first = grid(3, lty=1,lwd=2),
          main = "... panel.first = grid(3, lty=1,lwd=2), ..")

     [... etc ...]
)
par(op)


Hope this helps,

Rui Barradas

Thomas Zumbrunn-3 wrote
--
View this message in context: http://r.789695.n4.nabble.com/package-grid-mirror-grob-objects-along-an-axis-tp4630866p4630870.html
Sent from the R help mailing list archive at Nabble.com.
#
Maybe my question was not concise enough. I was referring to objects created 
with the "package "grid" (also called "grobs"), not to the function "grid" 
from package "graphics". For instance, let's say I have a polygon createad 
with grid::polygonGrob and want to mirror it along a specified axis. Of course 
one could transform the polygon's coordinates, but I was hoping that there is 
some more generic way of doing this (and that this could e.g. also be done 
with text grobs).

Cheers
/thomas
On Tuesday 22 May 2012, Rui Barradas wrote:

  
    
#
You can rotate the viewport to flip around the horizontal axis,

library(grid)
grid.text("Chiral")
grid.text("Chiral", vp=viewport(angle=180, y=unit(0.5,"npc")-unit(1,"line")))

HTH,

b.
On 23 May 2012 05:34, Thomas Zumbrunn <t.zumbrunn at unibas.ch> wrote:
#
Oops, sent too early; this obviously just a rotation, not a mirror
image. It illustrates the problem though ;)

b.
On 23 May 2012 07:32, baptiste auguie <baptiste.auguie at googlemail.com> wrote: