

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: http://www.flickr.com/photos/gonzillaaa/4397357491/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.
Many thanks,
Gonzalo.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On 03/01/2010 10:16 PM, Gonzalo GarciaPerate 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:
> http://www.flickr.com/photos/gonzillaaa/4397357491/>
> 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.
>
>
Hi Gonzalo,
The plotting functions try to space the axis tick labels so that there
is no crowding or overlapping. One way to get around this is to not
display the x axis on the initial plot (xaxt="n") and then add a custom
axis. One function that you can use is staxlab in the plotrix package.
staxlab(1,at=0:23,labels=0:23)
although you may want nlines=3 if you are willing to adjust the x axis
label.
Jim
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by Gonzalo GarciaPerate
On 3/1/2010 6:16 AM, Gonzalo GarciaPerate 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:
> http://www.flickr.com/photos/gonzillaaa/4397357491/>
> 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)
?axis

Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 8454495 (Tu, Th)
tel: (732) 5120171 (M, W, F)
fax: (917) 4380894
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thank you both for your help, axis did the trick very nicely.
On 1 March 2010 11:34, Chuck Cleland < [hidden email]> wrote:
> On 3/1/2010 6:16 AM, Gonzalo GarciaPerate 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:
>> http://www.flickr.com/photos/gonzillaaa/4397357491/>>
>> 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)
>
> ?axis
>
>> Many thanks,
>>
>>
>> Gonzalo.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide
>> http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, reproducible code.
>
> 
> Chuck Cleland, Ph.D.
> NDRI, Inc. (www.ndri.org)
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 8454495 (Tu, Th)
> tel: (732) 5120171 (M, W, F)
> fax: (917) 4380894
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

