如何在ggplot2中删除点并扩展箱形图 [英] How to remove dots and extend boxplots in ggplot2

查看:1893
本文介绍了如何在ggplot2中删除点并扩展箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据,我正在试图建立一些盒子图,但我得到这个错误:


警告信息:删除了包含非限定值的1631行
(stat_boxplot)。

没有 NA 值和所有数据似乎很好。我该如何解决这个问题,因为这些数据在我的数据中肯定是有价值的,并且应该由晶须扩展?
$ b

数据



数据相当大,我无法获得更小的子样本来产生错误,所以我只会发布原始数据。





编辑



我能够使用`range = 6'在 boxplot 中工作。有没有办法在ggplot中做到这一点?

  boxplot(dev〜year,data = d,range = 6)

解决方案

删除 ylim 限制,并使用 coef 参数 geom_boxplot ,那么它工作正常:

  library(ggplot2)
download.file(url =https://www.dropbox.com/s/5mgogyclhim6hom/dat.rds?dl=1,tf< - tempfile(fileext =.rds))
dat< - readRDS(tf)
ggplot(dat,aes(x = factor(year),y = dev))+
geom_boxplot(coef = 6)


I have some data that I'm trying to build some boxplots with, but I'm getting this error:

Warning message: Removed 1631 rows containing non-finite values (stat_boxplot).

There are no NA values and all the data seems fine. How can I fix this as these are certainly valuable points in my data and should be extended by the whiskers?

Data

The data is fairly large, and I couldn't get a smaller subsample to produce the errors, so I'll just post the original data.

dat.rds

ggplot2

dat <- readRDS("./dat.rds")
ggplot(dat, aes(x = factor(year), y = dev)) + geom_boxplot() + ylim(-40, 260)

Edit

I was able to get it to work in boxplot with `range = 6'. Is there a way to do this in ggplot?

boxplot(dev~year, data = d, range = 6)

解决方案

Remove the ylim restriction and use the coef argument of geom_boxplot, then it works fine:

library(ggplot2)
download.file(url = "https://www.dropbox.com/s/5mgogyclhim6hom/dat.rds?dl=1", tf <- tempfile(fileext = ".rds"))
dat <- readRDS(tf)
ggplot(dat, aes(x = factor(year), y = dev)) + 
  geom_boxplot(coef = 6) 

这篇关于如何在ggplot2中删除点并扩展箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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