ggplot: remove NA factor level in legend

后端 未结 3 466
说谎
说谎 2020-12-31 03:13

How can I omit the NA level of a factor from a legend?

From the nycflights13 database, I created a new continuous variable called

3条回答
  •  一生所求
    2020-12-31 03:44

    I like @Artem's method above, i.e., getting to the bottom of why there are NA's in your df. However, sometimes you know there are NA's, and you just want to exclude them. In that case, simply using 'na.omit' should work:

    na.omit(flights) %>% ggplot() +
    geom_bar(mapping = aes(x = carrier, fill = delay_class), position = "fill")
    

提交回复
热议问题