我正在嘗試向 ggplot 中的箱線圖添加樣本大小標簽。我擁有我認為需要的一切,但我不確定如何精細調整標簽的位置。我嘗試了 position_nudge 和 position_jitter,但我希望能夠單獨調整每個標簽,這樣我就不必擔心標簽會進入均值條。
我的資料代碼給了我這個 
give.n <- function(x){
return(c(y = mean(x), label = length(x)))
}
ggplot(ratings_county_2019_DI, aes(x=county, y=di))
geom_boxplot(aes(fill = county), fatten = 1.25)
scale_fill_manual(values = col19, aesthetics = c("colour", "fill"))
labs(x = "County", y = " DSI (%)")
theme_minimal()
theme(legend.position = "top")
stat_summary(fun.data = give.n, geom = "text")
ggtitle("Disease Serverity Index 2019 Survey")
theme(plot.title = element_text(hjust = 0.5))
uj5u.com熱心網友回復:
如果您提供position = position_nudge(y = VECTOR_OF_NUDGES)它可能會提供您正在尋找的控制元件。
give.n <- function(x){
return(c(y = mean(x), label = length(x)))
}
ggplot(mtcars, aes(x=as.character(gear), y=mpg))
geom_boxplot(aes(fill = cyl), fatten = 1.25)
stat_summary(fun.data = give.n, geom = "text",
position = position_nudge(y = c(0, -2.5, -1)))

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/376441.html
下一篇:從ggtree圖中洗掉“a”
