On Jan 18, 2008 4:49 PM, <darteta001 at ikasle.ehu.es>
wrote:> Dear list,
>
> I have a categorical variable in a data.frame that I would like to
> plot using a histogram to show number of events. Values are 0, 1 and
> some NAs. I can?t make the hist() function to
> 1) include a column with the number of NAs
> 2) have the x axis to be categorical, I always get 0, 0.2, 0.4,... 1
> divisions
>
> Can anyone help me?
>
> This is my code. "database" is my data.frame and
"Event" is my
> variable.
> attach(database)
> hist(Event, col = 2, main = "Number of Events"))
>
> Thanks in advance,
>
> David
Please read ?hist, especially the line:
"Typical plots with vertical bars are not histograms. Consider barplot
or plot(*, type = "h") for such bar plots. ". But no worry,
I've mixed
them up myself a number of times.
To get a column of NA's, see the following:
###Example:
sample.data<-as.factor(sample(c(1,0,NA),100,replace=T))
sample.data<-as.character(sample.data)
sample.data[is.na(sample.data)]<-" NA"
sample.data<-factor(sample.data)
plot(sample.data)
#####
/Gustaf
--
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik