我正在绘制一个分类变量。没有NA
但是情节出现NA
条,没有任何观察。如何在我的情节中停止对此NA
进行打印?
ggplot(data.frame(cat.hour),
aes(x=factor(cat.hour, levels=c("1 min","2 min","3 min","4 min","5 min","6 min","7 min","8 min","9 min","10 min")))) +
geom_bar(fill="lightgreen")
答案 0 :(得分:0)
正如您在电话unique(cat.hour)
中看到的那样,您的数据中存在NA。
过滤非NA值将是您的绘图的简单解决方法。但是,我鼓励您在情节之外进行计算。
require(ggplot2)
require(dplyr)
require(magrittr)
cat.hour %>%
na.omit() %>%
mutate(variable = factor(variable, levels=c("1 min","2 min","3 min","4 min","5 min","6 min","7 min","8 min","9 min","10 min"))) -> cat.hour
g <- ggplot(cat.hour, aes(x = variable))
g <- g + geom_bar(fill = "lightgreen")
g