NA's are being plotted in boxplot ggplot2

青春壹個敷衍的年華 提交于 2019-12-03 23:24:09
בנימן הגלילי

You may try to use the subset() function in the first line of your code

ggplot(data=subset(data, !is.na(luse)), aes(x=luse, y=rich))+

as suggested in: Eliminating NAs from a ggplot

You can also use the filter() function in dplyr/tidyverse:

data %>% filter(is.na(luse) == FALSE) %>% 
   ggplot(aes(x=luse, y=rich)) +
   geom_boxplot()

This way you don't have to create a new object.

Here is a formal answer using the comments above to incorporate !is.na() with filter() from tidyverse/dplyr. If you have a basic tidyverse operation such as filtering NAs, you can do it right in the ggplot call, as suggested, to avoid making a new data frame:

ggplot(data %>% filter(!is.na(luse)), aes(x = luse, y = rich)) + geom_boxplot()

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!