我有這部分代碼可以用我的資料生成箱線圖:
p <- ggplot(meltData, aes(x=variable, y=value))
geom_boxplot() geom_boxplot(outlier.colour="red", outlier.shape=1,outlier.size=2)
stat_summary(geom="text", fun=quantile,
aes(label=sprintf("%1.1f", ..y..), color=factor(variable)),
position=position_nudge(x=0.0), size=3.5,show_guide = FALSE)
ggtitle("Species measurements")
ggeasy::easy_center_title()
p
我有這個輸出:
我希望能夠在我的箱線圖上看到上下須數作為最大值和最小值(而不是例外值)。例如,在第 5 個箱線圖上,我們可以看到最大值為 72,但這是一個例外值,最大值應約為 56。
uj5u.com熱心網友回復:
如果我正確理解您的目的,您希望創建箱線圖以及顯示上下胡須編號的文本,并且圖中不應顯示例外值。如果這是真的,那么我同意@Death Metal 的觀點,您可能想要過濾每個類別的例外值。
但是,由于您不提供可重現的資料,因此這里有一個與您的資料類似的虛擬資料。
dat <- data.frame(var.A = c(iris$Sepal.Length, c(20,21,22)),
var.B = c(iris$Petal.Length, c(20,21,22)))
meltData <- dat %>% pivot_longer(cols = c(var.A, var.B),
values_to = "value",
names_to = "variable")
ggplot(meltData, aes(x=variable, y=value)) geom_boxplot()
這清楚地顯示了例外值
以下是在應用箱線圖之前過濾例外值的方法:
meltData %>% group_by(variable) %>%
filter(value != (boxplot(value))$out) %>%
ggplot(aes(x = variable, y = value))
geom_boxplot() stat_summary(geom="text",
fun=quantile,aes(label=sprintf("%1.1f", ..y..),
color=factor(variable)),
position=position_nudge(x=0.0),
size=3.5,show_guide = FALSE)
ggtitle("Species measurements")
ggeasy::easy_center_title()
#Warning message:
#`show_guide` has been deprecated. Please use `show.legend` instead.
結果:
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/477223.html
上一篇:包裝的ggplot,行間填充
下一篇:Rggplot2堆疊列而不是分組