I have been searching for the R manual, unable to solve my problem. Questions 1) How can I put the x axis at the top of the plot? 2) I am plotting data from a CTD. I want to add series sal, obs and fluo at the same plot by using points(sal,deepth) ets. The data have different values so I want to use multiple x axis (4) with different scaling. How can I do that? plot(sal,depth,ylim=c(100,0),xlim=c(-0.0120,62),type="l",col.axis="",xaxt="s",xlab="") points(temp,depth,type="l",col="red") points(obs,depth,type="l",col="green") points(fluo,depth,type="l",col="blue") Thank you for any help! Ener Borg
On 5/14/2007 7:45 AM, Ener Borg wrote:> I have been searching for the R manual, unable to solve my problem. > > Questions > > 1) How can I put the x axis at the top of the plot?To stop it from being at the bottom: axes=FALSE in the plot() call. To draw the box: box() To draw an axis on the left: axis(2). To draw an axis on the top: axis(3).> > 2) I am plotting data from a CTD. I want to add series sal, obs and fluo > at the same plot by using points(sal,deepth) ets. The data have > different values so I want to use multiple x axis (4) with different > scaling. How can I do that?The axis() function has a variety of arguments to let you place multiple axes on one plot. You'll need to do the rescaling of the data to a common scale yourself, then convert the desired tickmarks (which you may have obtained from the pretty() function) to that scale. For example, x1 <- rnorm(10, mean=10) x2 <- rnorm(10, mean=100, sd=10) x2adj <- x2/10 y <- rnorm(10) plot(x1, y, xlim=range(c(x1,x2adj)), pch="1", axes=F) box() axis(2) ticks <- pretty(x1) axis(1, at=ticks) points(x2adj, y, pch="2") ticks <- pretty(x2) axis(3, at=ticks/10, labels=ticks) mtext("x2", side=3, line=3)> > plot(sal,depth,ylim=c(100,0),xlim=c(-0.0120,62),type="l",col.axis="",xaxt="s",xlab="") > points(temp,depth,type="l",col="red") > points(obs,depth,type="l",col="green") > points(fluo,depth,type="l",col="blue") > > Thank you for any help! > > Ener Borg > > ______________________________________________ > 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.
Hi r-help-bounces at stat.math.ethz.ch napsal dne 14.05.2007 13:45:25:> I have been searching for the R manual, unable to solve my problem. > > Questions > > 1) How can I put the x axis at the top of the plot?see ?axis> > 2) I am plotting data from a CTD. I want to add series sal, obs and fluo > at the same plot by using points(sal,deepth) ets. The data have > different values so I want to use multiple x axis (4) with different > scaling. How can I do that? > >plot(sal,depth,ylim=c(100,0),xlim=c(-0.0120,62),type="l",col.axis="",xaxt="s",xlab="")> points(temp,depth,type="l",col="red") > points(obs,depth,type="l",col="green") > points(fluo,depth,type="l",col="blue")Strange, usually people want multiple y axes. Maybe you could look at setting 4 panels for plotting e.g. par(mfrow=c(2,2)) before doing your actual plot. If you insist on plotting 4 lines with 4 x axes into one plot then you need to make some adjustment prior plotting. You shall scale sal, temp, obs and fluo into some comparable figures e.g. to 0-1 and after plotting you need to add 4 axes with correct numbers (see at parameter). Adding 2 x axes (top and bottom) is strightforward, however adding next 2 x axes seems to be tricky (you probably need to use combination of lines and segments). Regards Petr> > Thank you for any help! > > Ener Borg > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Quoting Ener Borg <ener.borg at bio.uio.no>:> I have been searching for the R manual, unable to solve my problem. > > Questions > > 1) How can I put the x axis at the top of the plot?as others indicated, check ?axis... the parameter 'pos=3' will display the axis on top> 2) I am plotting data from a CTD. I want to add series sal, obs and fluo > at the same plot by using points(sal,deepth) ets. The data have > different values so I want to use multiple x axis (4) with different > scaling. How can I do that? > > plot(sal,depth,ylim=c(100,0),xlim=c(-0.0120,62),type="l",col.axis="",xaxt="s",xlab="") > points(temp,depth,type="l",col="red") > points(obs,depth,type="l",col="green") > points(fluo,depth,type="l",col="blue")in addition to what others have suggested, you may use: par(new=T) (check ?par) this will allow you to superimpose a plot on another. You can then do a first plot with your first set of points, then call par(new=T), and plot your second set of points whilst setting the axis type to "none", so the axes are not ploted. Then you can use 'axis' to display a new axis in teh position you want for the new range of points... repeat if needed for other sets. I hope this sets you in the right direction. Jose -- Dr. Jose I. de las Heras Email: J.delasHeras at ed.ac.uk The Wellcome Trust Centre for Cell Biology Phone: +44 (0)131 6513374 Institute for Cell & Molecular Biology Fax: +44 (0)131 6507360 Swann Building, Mayfield Road University of Edinburgh Edinburgh EH9 3JR UK