r - 更改 geom_boxplot 中的 mustache 末端

标签 r boxplot outliers

geom_boxplot

我正在尝试使用geom_boxplot来绘制图片。但是,我想更改晶须的定义,这意味着晶须的末端是我的数据的最大值和最小值,并且应该删除异常值。基于我现有的代码会很好。

非常感谢。

con.for2=data.frame(d=as.character(gl(9,20)),close=exp(rnorm(180)),open=exp(rnorm(180)))
concentration=melt(con.for2)
colnames(concentration)=c("location","Condition","formaldehyde")
p=ggplot(data=concentration,aes(factor(location), formaldehyde),ylim=c(0,0.15),cex.axis=1.5,cex.lab=15
         ) + geom_boxplot(aes(fill = Condition))+xlab("Location") + ylab("Formaldehyde concentration (mg/m3)")

最佳答案

改编自答案Changing whisker definition in geom_boxplot

 p <- ggplot(data=concentration,aes(factor(location), formaldehyde),ylim=c(0,0.15),cex.axis=1.5,cex.lab=15)

f <- function(x) {
  r <- quantile(x, probs = c(0, 0.25, 0.5, 0.75, 1))
  names(r) <- c("ymin", "lower", "middle", "upper", "ymax")
  r
}

p + stat_summary(fun.data=f, aes(fill= Condition), geom="boxplot", position="dodge")

enter image description here

关于r - 更改 geom_boxplot 中的 mustache 末端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44176312/

相关文章:

r - 种子在随机森林中起什么作用?

r - 如何清除所有属性?

r - ggplot barplot中y轴的顺序错误

r - 在 R 中将箱线图与直方图组合/叠加

algorithm - 使用 ELKI 进行离群值检测

database - 检测稀疏分布中的异常值?

r - 基于字符向量进行子集化时,knit_expand 失败

r - 在 R 中更改箱线图字体

r - 忽略 ggplot2 boxplot + faceting + "free"选项中的异常值

相当于 MATLAB 的 robustfit 的 Java 或 C