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")
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.
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.
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.
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()
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