我想绘制一个条形图,其中显示了男性、女性和 NA 的数量。问题是,当我添加fill=gender
用于着色条的选项时,我失去了 NA 条。我应该使用什么选项来保持 NA 栏也有颜色?
name <- c("Paul","Clare","John","What","Are","Robert","Alice","Jake")
gender <- c("male","female","male",NA,NA,"male","female","male")
df <- data.frame(name,gender)
ggplot(subset(df, gender=="male" | gender=="female" | is.na(gender)), aes(x=gender, fill=gender)) +
geom_bar() +
labs(x=NULL, y="Frequency") +
scale_fill_manual(values=c("red", "blue", "black"))