Wonsang You
2010-Aug-31 10:26 UTC
[R] How to Adaptively Set Up the Coordinate Range of Multiple Graphs in One Figure
Hi, R-Helpers, I would like to ask about multiple graphs in one figure. I tried to execute the following codes. xlim <- c(1,100) ylim <- c(1,4) plot(NA, xlim=xlim, ylim=ylim)> x <- c(1:100)for(j in seq(1,10,by=1)) { y <- j*x^2+log(j) lines(x, y) } In the above codes, I had to arbitrarily set up the coordinate range of the figure in advance before calculating the values y. (seexlim and ylim) In results, the figure did not contain all data since most of data were outside the predefined range. I am wondering about how to control xlim and ylim adaptive to the real range of data, in order to include all data in the figure. Thank you for your great help and contribution. Best Regards, Stephen You ----- -- Wonsang You Special Lab Non-Invasive Brain Imaging Leibniz Institute for Neurobiology http://www.ifn-magdeburg.de -- View this message in context: http://r.789695.n4.nabble.com/How-to-Adaptively-Set-Up-the-Coordinate-Range-of-Multiple-Graphs-in-One-Figure-tp2401337p2401337.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Philipp Pagel
2010-Aug-31 10:35 UTC
[R] How to Adaptively Set Up the Coordinate Range of Multiple Graphs in One Figure
On Tue, Aug 31, 2010 at 03:26:12AM -0700, Wonsang You wrote:> In the above codes, I had to arbitrarily set up the coordinate range of the > figure in advance before calculating the values y. (seexlim and ylim) > In results, the figure did not contain all data since most of data were > outside the predefined range. > I am wondering about how to control xlim and ylim adaptive to the real range > of data, in order to include all data in the figure.You do that by not specifying xlim and ylim - in that case R will calculate them based on your data. Maybe I did not understand waht exactly you want to get but if you explicitly set the limits that's what R is going to use. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/
baptiste auguie
2010-Aug-31 10:37 UTC
[R] How to Adaptively Set Up the Coordinate Range of Multiple Graphs in One Figure
Hi, It's easy with ggplot2, library(ggplot2) ## create an empty plot p <- ggplot(map=aes(x,y)) ## create a dummy list of data.frames with different ranges d <- replicate(4, data.frame(x=sample(1:10,1)+rnorm(10), y=sample(1:10,1)+rnorm(10)), simplify=FALSE) ## add lines to the plot step by step for(ii in seq_along(d)) p <- p + geom_line(data = d[[ii]], color=ii) HTH, baptiste On 31 August 2010 12:26, Wonsang You <you at ifn-magdeburg.de> wrote:> > Hi, R-Helpers, > > I would like to ask about multiple graphs in one figure. I tried to execute > the following codes. > > ?xlim <- c(1,100) > > ylim <- c(1,4) > > plot(NA, xlim=xlim, ylim=ylim) > > >> x <- c(1:100) > > for(j in seq(1,10,by=1)) { > > ? ? y <- j*x^2+log(j) > > ? ? lines(x, y) > > } > > > In the above codes, I had to ?arbitrarily set up the coordinate range of the > figure in advance before calculating the values y. (seexlim and ylim) > In results, the figure did not contain all data since most of data were > outside the predefined range. > I am wondering about how to control xlim and ylim adaptive to the real range > of data, in order to include all data in the figure. > Thank you for your great help and contribution. > > Best Regards, > Stephen You > > > ----- > -- > Wonsang You > Special Lab Non-Invasive Brain Imaging > Leibniz Institute for Neurobiology > http://www.ifn-magdeburg.de > -- > View this message in context: http://r.789695.n4.nabble.com/How-to-Adaptively-Set-Up-the-Coordinate-Range-of-Multiple-Graphs-in-One-Figure-tp2401337p2401337.html > Sent from the R help mailing list archive at Nabble.com. > > ? ? ? ?[[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. >-- ____________________ Dr. Baptiste Augui? Departamento de Qu?mica F?sica, Universidade de Vigo, Campus Universitario, 36310, Vigo, Spain tel: +34 9868 18617 http://webs.uvigo.es/coloides
Jim Lemon
2010-Aug-31 10:44 UTC
[R] How to Adaptively Set Up the Coordinate Range of Multiple Graphs in One Figure
On 08/31/2010 08:26 PM, Wonsang You wrote:> > Hi, R-Helpers, > > I would like to ask about multiple graphs in one figure. I tried to execute > the following codes. > > xlim<- c(1,100) > > ylim<- c(1,4) > > plot(NA, xlim=xlim, ylim=ylim) > > >> x<- c(1:100) > > for(j in seq(1,10,by=1)) { > > y<- j*x^2+log(j) > > lines(x, y) > > } > > > In the above codes, I had to arbitrarily set up the coordinate range of the > figure in advance before calculating the values y. (seexlim and ylim) > In results, the figure did not contain all data since most of data were > outside the predefined range. > I am wondering about how to control xlim and ylim adaptive to the real range > of data, in order to include all data in the figure.Hi Stephen, One easy way is: xlim<-range(x) ylim<-range(y) Jim
Greg Snow
2010-Aug-31 19:17 UTC
[R] How to Adaptively Set Up the Coordinate Range of Multiple Graphs in One Figure
The best approach is to calculate the limits before doing any plotting and set them appropriately. You could use your loop to compute y, but instead of calling lines, store the values, then use a function like matplot (or ggplot2 or lattice) to do the plotting. If you really need to change the limits after the fact (again it is better the other way), there is the zoomplot function in the TeachingDemos package, the 2nd example on the help page does what you describe. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Wonsang You > Sent: Tuesday, August 31, 2010 4:26 AM > To: r-help at r-project.org > Subject: [R] How to Adaptively Set Up the Coordinate Range of Multiple > Graphs in One Figure > > > Hi, R-Helpers, > > I would like to ask about multiple graphs in one figure. I tried to > execute > the following codes. > > xlim <- c(1,100) > > ylim <- c(1,4) > > plot(NA, xlim=xlim, ylim=ylim) > > > > x <- c(1:100) > > for(j in seq(1,10,by=1)) { > > y <- j*x^2+log(j) > > lines(x, y) > > } > > > In the above codes, I had to arbitrarily set up the coordinate range > of the > figure in advance before calculating the values y. (seexlim and ylim) > In results, the figure did not contain all data since most of data were > outside the predefined range. > I am wondering about how to control xlim and ylim adaptive to the real > range > of data, in order to include all data in the figure. > Thank you for your great help and contribution. > > Best Regards, > Stephen You > > > ----- > -- > Wonsang You > Special Lab Non-Invasive Brain Imaging > Leibniz Institute for Neurobiology > http://www.ifn-magdeburg.de > -- > View this message in context: http://r.789695.n4.nabble.com/How-to- > Adaptively-Set-Up-the-Coordinate-Range-of-Multiple-Graphs-in-One- > Figure-tp2401337p2401337.html > Sent from the R help mailing list archive at Nabble.com. > > [[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.