NA正被绘制在boxplot ggplot2中 [英] NA's are being plotted in boxplot ggplot2

查看:142
本文介绍了NA正被绘制在boxplot ggplot2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ggplot2中绘制一个v。简单的boxplot。我有物种丰富与土地利用类。但是,我的数据中有2个NA。出于某种奇怪的原因,即使他们被R理解为NA,他们也会被绘制出来。任何建议将其删除?



我使用的代码是:

  ggplot(data ,aes(x = luse,y = rich))+ 
geom_boxplot(mapping = NULL,data = NULL,stat =boxplot,position =dodge,outlier.colour =red,outlier.shape = 16,outlier.size = 2,notch = F,notchwidth = 0.5)+
scale_x_discrete(luse,drop = T)+
geom_smooth(method =loess,aes(group = 1 ))

但是,该图包含2个用于luse的NA。不幸的是我不能发布图片,但想象一下NA图吧被添加到我的图中。 您可以尝试使用 subset()函数在您的代码的第一行

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

建议如下:从ggplot中消除新生


I'm trying to plot a v. simple boxplot in ggplot2. I have species richness vs. landuse class. However, I have 2 NA's in my data. For some strange reason, they're being plotted, even when they're being understood as NA's by R. Any suggestion to remove them?

The code I'm using is:

ggplot(data, aes(x=luse, y=rich))+
  geom_boxplot(mapping = NULL, data = NULL, stat = "boxplot", position = "dodge", outlier.colour = "red", outlier.shape = 16, outlier.size = 2, notch = F, notchwidth = 0.5)+
  scale_x_discrete("luse", drop=T)+
  geom_smooth(method="loess",aes(group=1))

However, the graph includes 2 NA's for luse. Unfortunately I cannot post images, but imagine that a NA bar is being added to my graph.

解决方案

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

这篇关于NA正被绘制在boxplot ggplot2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆