How do you extend the axis line in R to cover the extent of your data? For example, in
my data goes to about 2100 and I would like the line for the x axis to go that far, but not make a tickmark or label at 2100. Is this even possible in R?
Here is the code used to make the above plot:
hist(x,breaks=50,xlab="...",main="",xlim=c(0,2100))
Thanks.
In this approach to set the axis limits of the given plot, the user here just simply use the xlim argument with the required parameters to set the limits of the x-axis limits and use the ylim argument with the required parameters to set the limits of the y-axis limits in the plot function of the R programming language ...
Use scale_xx() functions It is also possible to use the functions scale_x_continuous() and scale_y_continuous() to change x and y axis limits, respectively.
ylim: Convenience function to set the limits of the y axis.
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. Parameters: …: if numeric, will create a continuous scale, if factor or character, will create a discrete scale.
You need to use two axis commands; one for the axis line and another for the ticks and labels.
set.seed(2); x <- rlnorm(1000, log(130))
hist(x, breaks=seq(0, 3000, by=200), xlim=c(0,2100), xaxt="n")
axis(1, at=c(0,2100), labels=c("",""), lwd.ticks=0)
axis(1, at=seq(0 , 2000, by=200), lwd=0, lwd.ticks=1)
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