更改胡须结束于 geom_boxplot
Changing whisker end in 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")
我正在尝试用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")