Plotting Data on an Angle

Figure 1. A line graph at a  30 degree angle.

Figure 1. A line graph on angle.

You can try to make your data more dynamic looking by taking the y-axis off the perpendicular. Of course, that might be bad judgement. This blog post does not advocate rotating the frame of reference for your data plots. It merely shows you how.

The example provided below uses the “grid” package. If you don’t have this installed already, you can do so by making sure you are connected to the internet, and then entering “install.packages(“grid”)” on the R command line. I figured out how to use the grid library commands in this example by referring to Murrell (2006).

R Script
#Example written by Allan Roberts, April 2013

library(grid);
pushViewport(viewport());
pushViewport(viewport(height=0.5,width=0.5,angle=30));
time = seq(0,1,0.05);
x = rnorm(21,0.5,0.1);
grid.lines(time,x);
grid.xaxis(gp=gpar(col=rgb(1,0,0)));
grid.yaxis(gp=gpar(col=rgb(0,0,1)));

Reference

Murrell, Paul. 2011. R Graphics, 2nd Edition. CRC Press.

Advertisements

2 thoughts on “Plotting Data on an Angle

  1. Well… since you asked:
    It should be possible to rotate just about any image in this way. (Not just graphs.) Also, in the “grid” system, you can define multiple view ports, including nested ones. Non-orthogonal rotations of a view port could come in handy for projections of map data viewed from one of the poles (for example). If you are familiar with principal component analysis, etc., you can probably think of some further applications relative to the display of multivariate data. Finally, the graphics library ggplot2 is built of the grid library, which is a good demonstration of the flexibility of the grid system. (The example in this post is a simple one, but you’ve got to start somewhere.)

    For a more practical post, check out Error Bars with R

    For a fun but pointless post check out Snowflakes with R

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s