All - When I plot something like a<-rnorm(5) b<-rnorm(5) plot(a,b,col = "red") points(10,-10) The last point is missing because it is out of range of the first plot. I just try to switch from Matlab to R. In Matlab, it always can automatic adjust the xlim and ylim for such case. Is it possible auto adjust in R? Otherwise keep tracking xlim and ylim is really annoying. Best, Haoda
Hi AFAIK you need to adjust xlim and ylim in first call of plot as the plot itself is not redrawn but you only add points (or other graphing objects like lines) to existing plot. If you know what you want to plot you can use xlim=range(all.values.you.want.to.plot) for "automatic" adjustment of plotting area during first plot call. Regards Petr r-help-bounces at r-project.org napsal dne 17.10.2008 06:06:51:> All - > > > When I plot something like > > a<-rnorm(5) > b<-rnorm(5) > plot(a,b,col = "red") > points(10,-10) > > The last point is missing because it is out of > range of the first plot. > > I just try to switch from Matlab to R. In Matlab, > it always can automatic adjust the xlim and ylim > for such case. > > Is it possible auto adjust in R? Otherwise > keep tracking xlim and ylim is really annoying. > > Best, > Haoda > > ______________________________________________ > R-help at r-project.org 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.
Haoda Fu wrote:> All - > > > When I plot something like > > a<-rnorm(5) > b<-rnorm(5) > plot(a,b,col = "red") > points(10,-10) > > The last point is missing because it is out of > range of the first plot. > > I just try to switch from Matlab to R. In Matlab, > it always can automatic adjust the xlim and ylim > for such case. > > Is it possible auto adjust in R? Otherwise > keep tracking xlim and ylim is really annoying. > >if you know the range in advance, you can specify it using the xlim and ylim parameters to plot. you can also use them in points (it doesn't cause an error), but it does not seem to have the desired effect of reshaping the plot. it's perhaps a pity it works this way, but you have to get used to it. or drop r if you find matlab better. vQ
There are some functions that will do this in 1 step, like matplot if the the data is formatted properly. ggplot has already been mentioned as another approach. If you want to stick with base graphics, there is a zoomplot function in the TeachingDemos package that will rescale a plot (zoom in or out) and works in this case:> library(TeachingDemos) > > a<-rnorm(5) > b<-rnorm(5) > plot(a,b,col = "red") > points(10,-10) > > zoomplot( range(a,10), range(b,-10) ) >If you want this a little more automatic, you can easily write a function which does the zooming and plotting both, a simple version of the function would be:> expandpoints <- function(x, y, ... ) {+ usr <- par('usr') + zoomplot( range(x,usr[1:2]), range(y,usr[3:4]) ) + points(x,y,...) + }> > plot(a,b,col="red") > expandpoints(10,-10) >If you are going to use this much, it should be modified to accept the same types of input as points and possibly do some other checking. Note also that this will be adding a little extra area around the old points as well unless the axis style is changed. Hope this helps, -- 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 Haoda Fu > Sent: Thursday, October 16, 2008 10:07 PM > To: r-help at r-project.org > Subject: [R] R plot > > All - > > > When I plot something like > > a<-rnorm(5) > b<-rnorm(5) > plot(a,b,col = "red") > points(10,-10) > > The last point is missing because it is out of > range of the first plot. > > I just try to switch from Matlab to R. In Matlab, > it always can automatic adjust the xlim and ylim > for such case. > > Is it possible auto adjust in R? Otherwise > keep tracking xlim and ylim is really annoying. > > Best, > Haoda > > ______________________________________________ > 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.