che sto cercando di posizionare le etichette su un terreno a barre in pila utilizzando questo approccio (anche se ora c'è un approccio migliore Sono aperto a che cosa mai):etichette Centro barre in pila (conteggi) ggplot2
Showing data values on stacked bar chart in ggplot2
Ecco la mia trama originale:
dat <- data.frame(with(mtcars, table(cyl, gear)))
ggplot(dat, aes(x = gear, fill = cyl)) +
geom_bar(aes(weight=Freq), position="stack") +
geom_text(position = "stack", aes(x = gear, y = Freq,
ymax = 15, label = cyl), size=4)
Ecco il mio tentativo di centrare le etichette in ogni sezione di riempimento:
dat2 <- ddply(dat, .(cyl), transform, pos = cumsum(Freq) - 0.5*Freq)
library(plyr)
ggplot(dat2, aes(x = gear, fill = cyl)) +
geom_bar(aes(weight=Freq), position="stack") +
geom_text(position = "stack", aes(x = gear, y = pos,
ymax = 15, label = cyl), size=4)
Come faccio a centrare le etichette in ogni sezione di riempimento?
Perfetto. Ero vicino a lì, ma non del tutto. +1 –