I have a "Y" variable with many values less than 50, and many fewer between 50 and 250.I'd like to plot those Y's against an X, with two scales on the Y axis---maybe 60% of the axis height for 0-50 and the top 40% for 50-250.(I can't use log(Y) because there are many zeroes, and that is the most desirable value.) I think I've seen plots done that way, but is there a way to create them in R? Thanks for any help. [[alternative HTML version deleted]]
One option is the gap.plot function in the plotrix package. On Tue, Feb 25, 2014 at 10:18 AM, David Parkhurst <parkhurs at imap.iu.edu> wrote:> I have a "Y" variable with many values less than 50, and many fewer > between 50 and 250.I'd like to plot those Y's against an X, with two > scales on the Y axis---maybe 60% of the axis height for 0-50 and the top > 40% for 50-250.(I can't use log(Y) because there are many zeroes, and > that is the most desirable value.) > > I think I've seen plots done that way, but is there a way to create them > in R? > > Thanks for any help. > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
Please be a good netizen and post plain text on the list. Jim can probably point you to some plotrix function that will do what you ask, but I would encourage you to plot the data twice rather than confusing the audience with nonlinear (discontinuous) scales in a single plot. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On February 25, 2014 9:18:50 AM PST, David Parkhurst <parkhurs at imap.iu.edu> wrote:>I have a "Y" variable with many values less than 50, and many fewer >between 50 and 250.I'd like to plot those Y's against an X, with two >scales on the Y axis---maybe 60% of the axis height for 0-50 and the >top >40% for 50-250.(I can't use log(Y) because there are many zeroes, and >that is the most desirable value.) > >I think I've seen plots done that way, but is there a way to create >them >in R? > >Thanks for any help. > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at 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.
> I have a "Y" variable with many values less than 50, and many fewer > between 50 and 250.I'd like to plot those Y's against an X, with two > scales on the Y axis---maybe 60% of the axis height for 0-50 and the top > 40% for 50-250.(I can't use log(Y) because there are many zeroes, and > that is the most desirable value.) >Hi David, You can't do this with gap.plot because the scale of the ordinate stays the same over its extent. You could do it with twoord.plot, but it is probably not a good idea. twoord.plot was written to allow the viewer to "eyeball" the relationship between two variables with different metrics on a common abcissa. What you describe above is two sections of the same plot of one variable with two different scales on the same axis. This kind of defeats the whole idea of representing a variable's values in some visual metric. Having been almost as negative as the logarithms you would need to represent your zeros, I will offer a few suggestions. If you are worried about crowding of large numbers of points in the lower portion of the plot, perhaps you could use smaller symbols (e.g. plot them with text using "." with adj=c(0.5,0)) or look at the count.overplot function in plotrix. I suppose you could use twoord.plot by breaking up the the values into two sets and adjusting the ylim on each side so that the two sets of values had a gap between them and then sticking in a "gap" style axis.break. I still don't think it would be fair to the data, and you don't want those data liberation people parading around your laboratory with pictures of helpless data being devoured by a Babbage Difference Engine. Jim
Imagine you were plotting two sets, (x1, y1) and (x2, y2) on the same plot, where x1 and x2 have the same range, but y1 and y2 need different axis scales. Here's an example that I think illustrates the idea. It's a long way from being general, and if I were making it into a function in a package, I would certainly find ways to parameterize the various y ranges. But I think it illustrates a way to accomplish what was requested. ## some fake data x <- 1:4 y <- c(1,105, 2, 130) is.lo <- y < 100 x1 <- x[is.lo] y1 <- y[is.lo] x2 <- x[!is.lo] y2 <- y[!is.lo] yl1 <- c(0,10) yl2 <- c(50,140) ya1 <- c(0,5) ya2 <- c(100,140) par(mar=c(5.1, 4.1, 4.1, 4.1)) plot(range(x), yl1, type='n', yaxt='n', ylab='', xlab='X') mtext('Low range of Y', side=2, line=2.5, adj=0.25) points(x1,y1) axis(2, pretty(ya1)) par(new=TRUE) ## this is the key "trick" ## I can now add data to the existing plot, ## using any data ranges I want plot(range(x), yl2, type='n', yaxt='n', xaxt='n', ylab='', xlab='') points(x2,y2, col='red') axis(4, pretty(ya2)) mtext('High range of Y', side=4, line=2.5, adj=0.75) One can build exactly what one wants using base R graphics tools. (And I decline to address questions of whether such a plot is a good way to present data) -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/25/14 9:18 AM, "David Parkhurst" <parkhurs at imap.iu.edu> wrote:>I have a "Y" variable with many values less than 50, and many fewer >between 50 and 250.I'd like to plot those Y's against an X, with two >scales on the Y axis---maybe 60% of the axis height for 0-50 and the top >40% for 50-250.(I can't use log(Y) because there are many zeroes, and >that is the most desirable value.) > >I think I've seen plots done that way, but is there a way to create them >in R? > >Thanks for any help. > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at 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.