library("dplyr")
library("ggplot2")
让我们从这个简单的情节开始:
faithful %>%
ggplot(aes(waiting, eruptions, color = eruptions > 3)) +
geom_point()
现在,让我们在类变量中引入一些缺少的值:
faithful_with_missings <-
faithful %>%
mutate(eruptions_class = ifelse(eruptions > 3, '>3', '<=3'),
eruptions_class = ifelse(rbinom(n(), 1, 0.9), eruptions_class, NA_character_))
##eruptions_class = as.factor(eruptions_class))
faithful_with_missings$eruptions_class %>% table(exclude = NULL)
#> .
#> <=3 >3 <NA>
#> 89 151 32
重做情节,但未命中:
ggplot(faithful_with_missings, aes(waiting, eruptions, color = eruptions_class)) +
geom_point()
我的问题是: 有没有一种方法可以绘制NA点,但在图例中省略NA?
我想要的输出是: