Skip to content

Newbie Question About Histograms

4 messages · pfc_ivan, Peter Alspach, Eik Vettorazzi

#
Hello everyone. Just have a question , cant figure out how to make this
histogram. 

I have this table, that i stored in a variable name new.data2. Table looks
like this

Year GeoArea SmpNo Month Gear Maturity Length Age YearC
1989       1   362    10   22        1    225   1  1988
1991       1   267    10   10        1    191   1  1990
1991       1   267    10   10        1    202   1  1990
1992       1   305    10    8        1    162   1  1991
1992       1   305    10    8        1    165   1  1991
1992       1   305    10    8        1    166   1  1991
1992       1   305    10    8        1    167   1  1991
1992       1   305    10    8        1    167   1  1991
1992       1   305    10    8        1    169   1  1991
1992       1   305    10    8        1    170   1  1991

Now I need to make a histogram of Length vs YearC. I would guess that Length
would be on the Y-axis and YearC variable would be on X-axis. I have tried
many different combinations with command 'hist' but im always getting error
" 'x' must be numeric " ... I think im getting that error because of the
header which is not numeric. Any help would be appreciated. Thanks guys. 

Ivan.
#
Also I forgot to say that The Y-axis values for each YearC would be the mean
value of all the Lenghts that happen in that YearC. Basically I cant figure
out how to put the mean values of Lengths for each YearC on Y axis. 

Thanks in advance!
#
Kia ora Ivan

I think you might want a barplot.

?hist

under 'See Also:' states:

     Typical plots with vertical bars are _not_ histograms.  Consider
     'barplot' or 'plot(*, type = "h")' for such bar plots.
 
[The online help in R is good.]

HTH ....

Peter Alspach
The contents of this e-mail are confidential and may be subject to legal privilege.
 If you are not the intended recipient you must not use, disseminate, distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received this
 e-mail in error, please notify the sender and delete all material pertaining to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.
#
How about

 > dta<-read.table("clipboard",header=T)
 > means<-aggregate(dta$Length,by=list(YearC=dta$YearC),FUN=mean)
 > barplot(means[,2],names.arg=means[,1])

you may have a look at ?barplot to see (lots of) options for fine tuning 
the plot.

hth.

pfc_ivan schrieb: