As an example, if I want to draw a plot with points 1-5 and add points 5-9, the following would work:
> plot(c(1,2,3,4,5), ylim=c(0,10))
> points(c(5,6,7,8,9))
However, if I don't know beforehand what numbers the to-be-added points will be (they could be 5-9, could also be 20-29), I can't set the ylim and xlim beforehand. I would like to be able to do something like the following (which does not work):
> plot(c(1,2,3,4,5))
> points(c(5,6,7,8,9), ylim=c(0,10))
Is something like this possible?
(Just for completeness.)
This is almost certainly impossible in R base graphics. Other answers point out that it's doable in
ggplot
. It might be possible in something like theplaywith
package, although a short bit of playing around hasn't shown me a way to do it.Would this be good enough? It treats the upper bound of ylim as a variable, but technically you would know ylim before adding the points:
You could also treat the lower bound of ylim the same way:
You can alter the axes limits in ggplot2. For example,
As Ben Bolker mentions, in base graphics, you definitely can't do it without additional packages.
with
ggplot2
you can modify the axis:then