[R] Bar Graph

Jim Lemon jim at bitwrit.com.au
Wed Nov 13 09:30:19 CET 2013


On 11/13/2013 07:20 PM, Keniajin Wambui wrote:
> The serialno represents each individual in the data set.The total
> count of the serialno will represent the whole sample
>
>   I want to do a graph to compare the total data (serialno) vs each of
> the remaining five variables yearly. i.e to show the total data
> (serialno) vs available data for one of the variables in the above
> case temp axilla.
>
> The above code plot count of temp_axilla yearly,how can I include
> serialno to be part of the plot?
>
> I have used
> library(ggplot2)
> library(foreign)
> utils package

Hi Keniajim,
It is not easy to work out what you want. If each serial number is an 
individual and you want the total number of individuals (dataset is 
"mydata"):

length(unique(mydata$serialno))

If you want the total number of individuals per year:

nind<-function(x) return(length(unique(x)))
year<-as.numeric(format(as.Date(mydata$date_admn,"%d-%b-%y"),"%Y"))
by(mydata$serialno,mydata$year,nind)

Perhaps this will give you a start.

Jim



More information about the R-help mailing list