Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend the length of a plot axis in R?

Tags:

plot

r

How do you extend the axis line in R to cover the extent of your data? For example, in

http://i.stack.imgur.com/xUvp3.png

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.

like image 961
spadequack Avatar asked Jan 04 '11 20:01

spadequack


People also ask

How do I change AXE limits in R?

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 ...

How do I change the Y axis scale in ggplot2?

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.

What is YLIM R?

ylim: Convenience function to set the limits of the y axis.

How do I use XLIM in R?

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.


1 Answers

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)

alt text

like image 179
Aaron left Stack Overflow Avatar answered Sep 23 '22 06:09

Aaron left Stack Overflow