Hello, How do I split a y-axis to plot data on different scales? Eg: x <- 1:10 y <- c(-0.01,0.79,0.74,0.55,-0.67,0.32,-0.47,-0.05,723,759) plot(x,y) I'd like to show these data on the same plot, but the way it's written, all contrast in the first 8 data points is lost. Can R split a y-axis for me? Thanks, Rashmi Rashmi Mathur Master's Candidate Fisheries Science and Management Research Group School of Resource and Environmental Management (REM) Simon Fraser University Burnaby, BC rashmim@sfu.ca http://www.rem.sfu.ca/fishgrp
> How do I split a y-axis to plot data on different scales?The short answer: you shouldn't. The whole point of plotting the data is so that you can compare them visually on the same scale. As soon as you split the scales you can no longer do this, and you effectively have two separate graphs. This suggests how you should solve your problem - create two graphs, one for each separate scale. Hadley
--- Rashmi Mathur <rashmim at sfu.ca> wrote:> Hello, > > How do I split a y-axis to plot data on different > scales? > > Eg: > > x <- 1:10 > y <- >c(-0.01,0.79,0.74,0.55,-0.67,0.32,-0.47,-0.05,723,759)> plot(x,y) > > I'd like to show these data on the same plot, but > the way it's written, all > contrast in the first 8 data points is lost. Can R > split a y-axis for me? > > Thanks, > Rashmi >As Hadley said: Don't. It can lead to misinterpretations. You are better off if you plot two graphs. Consider something like using par(mfrow)and place the two graphs one above the other on the same page. This will let you use a common x-axis but avoids the split problem. Quick and dirty example: x <- c(1:10) y <- c(1:10) z <- c(21:30) par(mfrow= c(2,1)) plot(x,y) plot(x,z) Have a look at Cleveland's book The Elements of Graphing Data (Revised Edition). W. S. Cleveland (1994). Hobart Press, Summit, New Jersey for some suggestions and the reason a split y-axis is not a good idea.
Rashmi Mathur wrote:> Hello, > > How do I split a y-axis to plot data on different scales? > > Eg: > > x <- 1:10 > y <- c(-0.01,0.79,0.74,0.55,-0.67,0.32,-0.47,-0.05,723,759) > plot(x,y) > > I'd like to show these data on the same plot, but the way it's written, all > contrast in the first 8 data points is lost. Can R split a y-axis for me? >Hi Rashmi, Although Hadley's answer is relevant (displaying vastly different ranges of data can be dangerous) you might find that gap.plot in the plotrix package will do the dirty deed. Jim
I think information can be enhanced by using different scaled graphs next to each other. mfrow() created too much space, there may be no need to again draw the x-axis. It can be very useful to have different scales of the same data presented next to each other, in addition to the main graph. So I think the data of the person who started this thread could be displayed using one graph will all the data, and then a superimposed graph (sharing same x-axis) on any part of the data to give an enhanced visual communication. Drawing grid lines with same tick marks in both graphs can enhance this visual communication. This is like "static zooming". Of course it is important to make sure that the change in scale is evident, because it is needed for the interpretation of the graph---using a grid with same tick marks can produce this effect visually. Anupam.
Gabor Grothendieck
2006-Aug-20 13:58 UTC
[R] split a y-axis to show data on different scales
Look at oma= and mar= parameters to par for controlling the space when using mfrow=. e.g. opar <- par(oma = c(6, 0, 5, 0), mar = c(0, 5.1, 0, 2.1), mfrow = c(2,2)) for(i in 1:4) plot(1:10) par(opar) On 8/20/06, Anupam Tyagi <AnupTyagi at yahoo.com> wrote:> I think information can be enhanced by using different scaled graphs next to > each other. mfrow() created too much space, there may be no need to again draw > the x-axis. It can be very useful to have different scales of the same data > presented next to each other, in addition to the main graph. So I think the data > of the person who started this thread could be displayed using one graph will > all the data, and then a superimposed graph (sharing same x-axis) on any part of > the data to give an enhanced visual communication. Drawing grid lines with same > tick marks in both graphs can enhance this visual communication. This is like > "static zooming". Of course it is important to make sure that the change in > scale is evident, because it is needed for the interpretation of the > graph---using a grid with same tick marks can produce this effect visually. > > Anupam. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >