0

I repeat I am new to R and did not figure out just yet all the idiosyncrasy of R. I do not know where I am missing the simple point here.

I try to plot a histogram with ggplot and do not manage to label my x axis properly and to get rid of the NA values I have (see small data set provided): http://ubuntuone.com/7iL1UG0YxHpKs0kXN8uQhC (8,2 KB)

sex <- factor(rawdata$Sesso)
ggplot(rawdata, aes(x=sex)) + geom_histogram() + xlab("") + ylab("Number of Persons") + ggtitle("Gender of Persons") + scale_x_discrete(breaks=c("1", "2", NA),labels=c("Male", "Female", "NA"))

I get either this: wrong plot or that: wrong plot2

This is what I tried so far to address that issue:

sex <- sex[complete.cases(sex),]
ggplot(na.omit(rawdata), aes(x=sex)) + geom_histogram() + xlab("") + ylab("Number of Persons") + ggtitle("Gender of Persons")
ggplot(rawdata[!is.na(rawdata$Sesso),], aes(x=rawdata$Sesso)) + geom_histogram() + xlab("") + ylab("Number of Persons") + ggtitle("Gender of Persons")
sex <- factor(rawdata$Sesso,exclude=NULL)

But to no avail!

Til Hund
  • 1,543
  • 5
  • 21
  • 37
  • I can't see any "NA" values, or values that will be read as NA in your example data set. Is "sconosciuto" the equivalent of what you mean by NA? – mnel Jan 06 '14 at 01:18
  • Does `sex <- droplevels(sex[complete.cases(sex),])` work instead of what you have? I suppose you have no none-`NA` data in the group that takes class `sconosciuto`. – Gavin Simpson Jan 06 '14 at 01:20
  • "Sconosciuto" means unknown and might be an equivalent to NA. But this it just one case, what I have a lot are NULL(?) values. A long list of empty values. @ Gavin Simpson, I executed the command and get an error I have encountered once before. "Error in `[.default`(sex, complete.cases(sex), ) : wrong numbers of dimensions". I do not know yet the inner concept of that issue which makes it difficult for me to find a fix. – Til Hund Jan 06 '14 at 01:54
  • Please `dput` a small sample of your data. See [**here**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – Henrik Jan 06 '14 at 07:20
  • As @mnel already said: there are no NA's in the small data set, which you provided. `geom_histogram` draws three bars: male, female and sconosciuto. – lukeA Jan 06 '14 at 10:12

0 Answers0