Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the ylim and xlim when the plot has already been drawn?

Tags:

plot

r

limit

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?

like image 300
Niek de Klein Avatar asked May 04 '12 13:05

Niek de Klein


People also ask

What does XLIM () do while plotting?

xlim( limits ) sets the x-axis limits for the current axes or chart. Specify limits as a two-element vector of the form [xmin xmax] , where xmax is greater than xmin .

How do you rescale a plot in Python?

MatPlotLib with Python To plot a line, use plot() method and data range from 0 to 10. To scale the xlim and ylim automatically, we can make the variable scale_factore=6. Use scale_factor (from Step 2) to rescale the xlim and ylim, using xlim() and ylim() methods, respectively. To display the figure, use show() method.

What is YLIM in plot?

The xlim() function with the provided parameters as the range of the x-axis in vectors is used to set the x-axis without dropping any data of the given plot or an object accordingly.


1 Answers

(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 the playwith package, although a short bit of playing around hasn't shown me a way to do it.

like image 127
Ben Bolker Avatar answered Oct 07 '22 23:10

Ben Bolker