R ggplot2-最小/最大值时的箱线图晶须
在ggplot2中,我希望将触须延伸到数据集的最小值和最大值,而不显示异常值。我已经找到了隐藏异常值的方法,但是我无法得到每个组的最小值和最大值R ggplot2-最小/最大值时的箱线图晶须,r,ggplot2,R,Ggplot2,在ggplot2中,我希望将触须延伸到数据集的最小值和最大值,而不显示异常值。我已经找到了隐藏异常值的方法,但是我无法得到每个组的最小值和最大值 a <- data.frame(group = "a", value = rnorm(10)) b <- data.frame(group = "b", value = rnorm(100)) c <- data.frame(group = "c", value = rnorm(1000)) data <- rbind(a,
a <- data.frame(group = "a", value = rnorm(10))
b <- data.frame(group = "b", value = rnorm(100))
c <- data.frame(group = "c", value = rnorm(1000))
data <- rbind(a, b, c)
ggplot(data, aes(x=group, y=value)) +
stat_boxplot(geom ='errorbar') +
geom_boxplot() #geom_boxplot(outlier.shape = NA)
a在LJW的评论之后,我想这就是你想要的:
a <- data.frame(group = "a", value = rnorm(10))
b <- data.frame(group = "b", value = rnorm(100))
c <- data.frame(group = "c", value = rnorm(1000))
data <- rbind(a, b, c)
o <- function(x) {
subset(x, x == max(x) | x == min(x))
}
f <- function(x) {
r <- quantile(x, probs = c(0.00, 0.25, 0.5, 0.75, 1))
names(r) <- c("ymin", "lower", "middle", "upper", "ymax")
r
}
ggplot(data, aes(x=group, y=value)) +
stat_summary(fun.data=f, geom="boxplot") +
stat_summary(fun.y = o, geom="point") +
stat_boxplot(geom='errorbar',coef=10) #just give an arbitrarily big number here
a您看过这个问题了吗?这个问题的答案确实将箱线图的范围扩展到了最小值和最大值,但是,胡须的错误条似乎没有跟随它,使范围条远远超出了错误条。谢谢您的回答。这确实正确地扩展了范围,但错误条不跟随,使范围扩展到错误条之外。(即统计箱线图(geom='errorbar'))