Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the intervals of x-axis using r

Tags:

I plot a distribution of visit time of a scenic spot from 0 to 23 hours in a day. And I want to adjust the intervals of x-axis letting all hours be displayed. How can I do that?

d = c(42,13,10,3,2,6,7,15,38,63,128,153,178,181,236,217,272,417,526,653,607,385,191,70) plot(seq(0,23,by=1),c,type='b',col='red',main="Confucius Temple",xlab="Hours",ylab="Numbers of check-in") 

enter image description here

like image 711
Joey.Z Avatar asked Mar 30 '13 10:03

Joey.Z


People also ask

How do you change the x-axis interval in R?

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

How do you set an AXE in R?

You can create custom axes using the axis( ) function. axis(side, at=, labels=, pos=, lty=, col=, las=, tck=, ...) the coordinate at which the axis line is to be drawn. If you are going to create a custom axis, you should suppress the axis automatically generated by your high level plotting function.

How do I change tick marks in R?

Option 1. Set xaxt = "n" and yaxt = "n" to remove the tick labels of the plot and add the new labels with the axis function. Note that the at argument sets where to show the tick marks.


1 Answers

You can use axis:

> axis(side=1, at=c(0:23)) 

That is, something like this:

plot(0:23, d, type='b', axes=FALSE) axis(side=1, at=c(0:23)) axis(side=2, at=seq(0, 600, by=100)) box() 
like image 198
Arun Avatar answered Sep 27 '22 19:09

Arun