Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the range (ylim) of a plot?

Tags:

plot

r

I am plotting a boxplot without the outliers and I would like to create a new plot in the same cartesian space as the boxplot did. Is there a way of extracting the plotting values for a plot?

I first thought about creating an object but there seems to be no plotting-related parameters.

my_plot <- boxplot(a ~ b, outline=F)

But the parameters inside my_plot only concern statistical information but not plotting.

How can I get the final range (ylim) of the boxplot?

UPDATE: Nick's @nick-sabbe suggestion (par("yaxp")[1:2]) partially works. It returns properly the value of each of the labels in each extreme on the Y-axis. The correct way is to use par('usr') as it returns the extremes of the plotting area in the form (x1, x2, y1, y2). Thanks Nick for pointing me into the right direction.

like image 983
pedrosaurio Avatar asked Dec 07 '11 12:12

pedrosaurio


1 Answers

I haven't tested this for boxplots, but for normal scatterplots, par("yaxp") gives you interesting information wrt the y axis. So you can use, IIRC, par("yaxp")[1:2] to get the current outer limits of the y axis. This doesn't always do exactly what you want, but typically it does. Let us know if it works for your boxplot...

like image 129
Nick Sabbe Avatar answered Oct 23 '22 02:10

Nick Sabbe