Re: [R] package grid: mirror grob objects along an axis
Hi, Another option that you might want to try is the tikzDevice package; tikz has functions to flip and rotate objects and could it from R with tikzAnnotate / tikzAnnotateGrob. Of course these objects would not really be grobs but tikz code, though for text the end result would probably be the same. Cheers, baptiste On 4 June 2012 08:22, Thomas Zumbrunn wrote: > 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@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 > > __ > R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] package grid: mirror grob objects along an axis
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@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 __ R-help@r-project.org 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.
Re: [R] package grid: mirror grob objects along an axis
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 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 wrote: >> 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: >>> 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-ax >>> is-tp4630866p4630870.html Sent from the R help mailing list archive at >>> Nabble.com. >>> >>> __ >>> R-help@r-project.org 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. >> >> >> -- >> Thomas Zumbrunn, PhD >> Clinical Trial Unit (CTU) >> Universitätsspital Basel >> Schanzenstr. 55, CH-4031 Basel >> Tel +41 (0)61 556 52 92 >> Fax +41 (0)61 265 94 10 >> http://www.clinicaltrialunit.ch/ >> >> __ >> R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] package grid: mirror grob objects along an axis
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 wrote: > 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: >> 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-ax >> is-tp4630866p4630870.html Sent from the R help mailing list archive at >> Nabble.com. >> >> __ >> R-help@r-project.org 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. > > > -- > Thomas Zumbrunn, PhD > Clinical Trial Unit (CTU) > Universitätsspital Basel > Schanzenstr. 55, CH-4031 Basel > Tel +41 (0)61 556 52 92 > Fax +41 (0)61 265 94 10 > http://www.clinicaltrialunit.ch/ > > __ > R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] package grid: mirror grob objects along an axis
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: > 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-ax > is-tp4630866p4630870.html Sent from the R help mailing list archive at > Nabble.com. > > __ > R-help@r-project.org 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. -- Thomas Zumbrunn, PhD Clinical Trial Unit (CTU) Universitätsspital Basel Schanzenstr. 55, CH-4031 Basel Tel +41 (0)61 556 52 92 Fax +41 (0)61 265 94 10 http://www.clinicaltrialunit.ch/ __ R-help@r-project.org 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.
Re: [R] package grid: mirror grob objects along an axis
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. __ R-help@r-project.org 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.