I am using the following code:
x <-sample(1:100, 10);
y <-sample(1:100, 10);
plot(x,y);
but I am trying to create a plot with static values on x, y axis. The problem is that sometimes x axis for example, is presented with a value range from 0 to 80 on the plot, while others from 20 to 100 depending to the random values inside x.
I would like both x, y, to have a value range from 0 to 100 in the plot in all cases, regardless of the values inside x and y matrices.
Is there a way to achieve this?
Thanks in advance!
Depending on what exactly you mean by "value range from 1 to 100", one of the following should do the trick.
In the first one, plot by default extends the axis limits by 4% at both ends
In the second one, xaxs="i" and yaxs="i" are used to suppress this behaviour. (See ?par for more details.)
plot(x,y, xlim=c(0,100), ylim=c(0,100))

plot(x,y, xlim=c(0,100), ylim=c(0,100), xaxs="i", yaxs="i")

There are two functions you can use, xlim() and ylim() within plot() which you can use to manually set your axes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With