我希望將數值添加到堆積條形圖中每個堆疊的中間(下面的代碼)。我發現的大多數示例都針對一列中的資訊,每當我嘗試修改它時,都會遇到有關長度要求的錯誤。
DA <- data.frame(
Imp=c("2015","2019"),
"mismatch"=c(220,209),
"match"=c(3465,3347),
"NA"=c(501,630),
check.names = FALSE)
DA %>%
pivot_longer(-Imp) %>%
ggplot(aes(x = Imp, y = value, fill = name)) geom_col(position = "stack")
scale_fill_manual(name=" ", values=c("aquamarine4", "orange", "coral"))
theme_light()
theme(legend.position = "bottom")
scale_y_continuous(expand = c(0,0))
geom_text(aes(x=1, y=4300, label="Stretch it"), vjust=-1)
labs(y="Count", x="Imputed Genotypes")
geom_bar(stat = "identity", color="white", width = 1)
uj5u.com熱心網友回復:
像這樣?
library(tidyverse)
DA <- data.frame(
Imp=c("2015","2019"),
"mismatch"=c(220,209),
"match"=c(3465,3347),
"NA"=c(501,630),
check.names = FALSE)
DA %>%
pivot_longer(-Imp) %>%
ggplot(aes(x = Imp, y = value, fill = name))
geom_col(color = "white", lwd = 1,
position = "stack", width = 0.75)
scale_fill_manual(name="", values=c("aquamarine4", "orange", "coral"))
scale_y_continuous(expand = c(0,0),
limits = c(0, 4200))
labs(y="Imputed Genotypes (Count)")
geom_text(aes(label = value), color = "white", size = 5,
position = position_stack(vjust = 0.5),
show.legend = FALSE)
theme_light(base_size = 18)
theme(legend.position = "right",
axis.title.x = element_blank())

由reprex 包(v2.0.1)于 2021 年 12 月 19 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/387226.html
上一篇:如何更改圖表中的開始月份
