Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting equal xlim and ylim in plot function

Tags:

plot

r

Is there a way to get the plot function to generate equal xlimand ylimautomatically? I do not want to define a fix range beforehand, but I want the plot function to decide about the range itself. However, I expect it to pick the same range for x and y.

like image 957
Milad Avatar asked Dec 05 '25 04:12

Milad


2 Answers

A possible solution is to define a wrapper to the plot function:

plot.Custom <- function(x, y, ...) {
  .limits <- range(x, y)
  plot(x, y, xlim = .limits, ylim = .limits, ...)
}
like image 179
B.Shankar Avatar answered Dec 07 '25 19:12

B.Shankar


One way is to manipulate interactively and then choose the right one. A slider will appear once you run the following code.

library(manipulate)
manipulate(
    plot(cars, xlim=c(x.min,x.max)),
    x.min=slider(0,15),
    x.max=slider(15,30))
like image 20
user227710 Avatar answered Dec 07 '25 19:12

user227710



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!