How to remove dots and extend boxplots in ggplot2

2019-08-15 07:20发布

This question already has an answer here:

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)

enter image description here

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)

enter image description here

1条回答
混吃等死
2楼-- · 2019-08-15 07:48

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) 

enter image description here

查看更多
登录 后发表回答