[R] Change the limits of a plot "a posteriori"

jcano javier.cano at urjc.es
Thu Dec 1 19:12:03 CET 2011


Hi all

How can I change the limits (xlim or ylim) in a plot that has been already
created?

For example, consider this naive example 
curve(dbeta(x,2,4))
curve(dbeta(x,8,13),add=T,col=2)

When adding the second curve, it goes off the original limits computed by R
for the first graph, which are roughly, c(0,2.1)

I know two obvious solutions for this, which are:
1) passing a sufficiently large parameter e.g. ylim=c(0,4) to the first
graphic
curve(dbeta(x,2,4),ylim=c(0,4))
curve(dbeta(x,8,13),add=T,col=2)

or 

2) switch the order in which I plot the curves
curve(dbeta(x,8,13),col=2)
curve(dbeta(x,2,4),add=T)

but I guess if there is any way of adjusting the limits of the graphic "a
posteriori", once you have a plot with the undesired limits, forcing R to
redraw it with the new limits, but without having to execute again the
"curve" commands

Hope I made myself clear

Best regards and thank you very much in advance


--
View this message in context: http://r.789695.n4.nabble.com/Change-the-limits-of-a-plot-a-posteriori-tp4129750p4129750.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list