我很难将文本放置到堆叠条形图的正确位置。具体来说,我想将这些ZipfColl_mean
值放入各自堆栈的中间:
library(viridis)
library(hrbrthemes)
library(ggplot2)
adj %>%
group_by(Struktur2) %>%
mutate(ZipfColl_mean = round(mean(ZipfColl),2)) %>%
ggplot(aes(fill=Struktur2, x=Adjektivsemantik))+
geom_bar(position = "stack", stat = "count") +
scale_fill_viridis(discrete = T, option = "E", name = "Structure", labels = c("full", "fragment", "topic drop")) +
geom_text(aes(x = Adjektivsemantik, y = ZipfColl_mean, label = ZipfColl_mean, color = "red"))+
ggtitle("") +
facet_grid(rows=vars(Feedbackposition), cols=vars(Referenzstruktur), switch="y") +
theme_ipsum() +
xlab("")
如何将这些ZipfColl_mean
值放入各自堆栈的中间?
数据:
adj <- structure(list(Struktur2 = structure(c(3L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 2L, 1L, 2L, 1L, 2L), levels = c("full",
"fragment", "topic_drop"), class = "factor"), Adjektivsemantik = structure(c(2L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), levels = c("descriptive", "evaluative"), class = "factor"),
Referenzstruktur = structure(c(1L, 2L, 2L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("individual",
"proposition"), class = "factor"), Feedbackposition = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
1L, 2L, 1L, 2L), levels = c("other", "feedback"), class = "factor"),
ZipfColl = c(4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43,
4.43, 4.43, 4.43, 5.61, 5.61, 5.61, 5.61, 5.61, 5.61, 5.61,
5.61, 5.61)), row.names = c(1L, 2L, 3L, 4L, 5L, 7L, 8L, 9L,
14L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 26L, 27L), class = "data.frame")
这是一种计算外部计数的方法,也
ggplot()
使用标签位置的计数:y
position = position_stack(vjust = .5)