嗨,標準化后,我似乎無法正確地將標簽添加到堆疊圖中。例如,
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition <- rep(c("normal" , "stress" , "Nitrogen") , 4)
value <- abs(rnorm(12 , 0 , 15))
data <- data.frame(specie,condition,value)
data$value = round ( data$value, 2 )
# Stacked percent
ggplot(data, aes(fill=condition, y=value, x=specie))
geom_bar(position="fill", stat="identity")
以上將產生一個標準化的堆疊圖但是當我添加
geom_text(aes(label=value),
position=position_stack(vjust=0.5))
它不符合規范化。有沒有辦法解決這個問題?它類似于鏈接,但不完全是因為我不需要計算而且我還添加了 stat="identity"
提前致謝。
uj5u.com熱心網友回復:
當你使用position="fill"你的酒吧時,你也必須使用position=position_fill(vjust=0.5)ingeom_text來定位你的標簽:
注意:我切換到geom_col哪個是一樣的geom_bar(..., stat="identity")
set.seed(123)
library(ggplot2)
# Stacked percent
ggplot(data, aes(fill = condition, y = value, x = specie))
geom_col(position = "fill")
geom_text(aes(label = value),
position = position_fill(vjust = 0.5)
)

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460964.html
上一篇:根據列條件洗掉行R-Studio
