Tenho dificuldade em colocar o texto nas posições corretas de um gráfico de barras empilhado. Especificamente, quero colocar os ZipfColl_mean
valores no meio de suas respectivas pilhas:
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("")
Como os ZipfColl_mean
valores podem ser colocados no meio de suas respectivas pilhas?
Dados:
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")
Aqui está uma abordagem que calcula as contagens fora do
ggplot()
uso das contagens paray
a posição dos rótulos, bem comoposition = position_stack(vjust = .5)
: