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> > 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 > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- 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.
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