How to remove NA from a factor variable (and from a ggplot chart)?

ggplot2, missing-data, r

Solution

assuming your data is in a data frame called `dat`

`newdat <- dat[!is.na(dat$Factor), ]`

not sure how to solve the problem inside of ggplot code

Problem

I have a problem with NA in a factor variable since ggplot includes them in the plot as if they are another category/level. I would like to drop the missing data. I am sorry I don't have code handy at the moment, I tried to remove factor levels from dataset that I found at `data()` and it did not work. Had someone the same problem? I tried the solution suggested here Remove unused factor levels from a ggplot bar plot but I get an error Error: unexpected symbol in: mycode Can someone suggest something? Also, if there is no way to remove them from inside the ggplot code, how can I remove the NA from a factor variable?

Original source

Related problems