tags:

views:

97

answers:

3

I searched for this and found that with {grid} there are ways to rotate an image, and that for some plots you can play with their rotation (for example plot(x,y) instead of plot(y,x)).

However, I want to know if there is a generic method to rotate a plot in R (one that would work for ANY plot generated in base graphics) ?

+3  A: 

I'm reasonably certain that there isn't a way with base graphics itself to do this generically. There is however the gridBase package which allows one to mix base graphics and grid graphics in a 'plot'. The vignette for the package has a section on embedding base graphics in grid viewports, so you might look there to see if you can cook up a grid wrapper around your plots and use grid to do the rotation. Not sure if this is a viable route but is, as far as I know, the on only potential route to an answer to your Q.

gridBase is on CRAN and the author is Paul Murrell, the author of the grid package.

After browsing the vignette, I note one of the bullets in the Problems and Limitations section on page, which states that it is not possible to embed base graphics into a rotated grid viewport. So I guess you are out of luck.

Gavin Simpson
Good answer! (although not the one I had liked to read) Thanks!
Tal Galili
+1  A: 

Given that its possible to write your own plot functions using base graphics, I can't see how a single solution could exist. Is what you want really just a way to rep lace x data with y data? What exactly do you mean by "rotate"?

Spacedman
rotate = to make the output plot be (for example) 90 degrees rotated.
Tal Galili
Do you mean the *whole* plot? Axes, text, tickmarks etc etc? That seems pointless on a screen graphics device, or on a postscript device you can probably use horizontal=TRUE/FALSE to produce a rotated plot relative to the paper. Or use the svg() graphics device and then load the svg file into inkscape, do select all and rotate 90 degrees. Those are all valid ways of making the output plot be 90 degrees rotated.
Spacedman
That is true - but I was wondering if there is a way for doing this in R :)
Tal Galili
+1  A: 

A function rotate_plot to be used like

rotate_plot(some_base_plot(x, y, ...))

isn't possible because most of the base plot don't return a value.

Some of the plots contain a horiz argument to allow you to choose which way round you want the plot drawing. Take a look at barplot.default to see how to implement this. (Warning: it's messy.)

@ucfagls's suggestion to use gridBase is your best bet. There are some examples of its use in Appendix B of Murrell's R Graphics.

Richie Cotton
Thank you Richie - I am sad of the answer, but it is an answer non the less. I'll mark as "answer" ucfagls answer for timing purposes. Best, Tal
Tal Galili