[R] setting the steps for x axis labels on plot
ccleland at optonline.net
Mon Mar 1 12:36:15 CET 2010
On 3/1/2010 6:16 AM, Gonzalo Garcia-Perate wrote:
> Hello, I'm new to R, I've been working with it for the last 2 weeks. I
> am plotting some data and not getting the labels on the x axis I am
> expecting on my plot.
> my code reads
> #hours in the day
> h <- c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23)
> #hp is a data frame with a pivot table of 25 columns (label and data for
> 24 hours)
> plot(h, as.matrix(hp[1,2:25]), main = hp[1,1], type="l", xlim=c(0,23),
> ylim=c(0,1800), xlab="hour", ylab="visitor activity")
> the result you can see here:
> I was hoping the steps on the x axis would be every hour or at least
> every two hours I am getting unevenly spaced steps (0, 5, 10, 20) instead.
> apologies if this is too obvious a question, I've looked around on
> documentation etc. but found no reference to this.
You can suppress the x axis in the call to plot() and then add it with
a call to axis(). For, example
plot(0:23, runif(24, min=0, max=1800), type="l", xlim=c(0,23),
ylim=c(0,1800), xlab="hour", ylab="visitor activity", xaxt='n')
axis(side=1, at=0:23, cex.axis=.5)
> Many thanks,
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help