【发布时间】:2022-01-21 07:14:48
【问题描述】:
我希望将数值添加到堆积条形图中每个堆栈的中间(代码如下)。我发现的大多数示例都针对一列中的信息,每当我尝试修改它时,都会遇到有关长度要求的错误。
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)
【问题讨论】: