[R] geom_text in ggplot (position)
AURORA GONZALEZ VIDAL
aurora.gonzalez2 at um.es
Tue May 12 18:50:48 CEST 2015
Hello everybody.
I have an "esthetic" question. I have managed to create a stacked and
grouped bar plot but I don't manage with putting the text in the middle of
the bar plots. Do you know how to write the numbers in that position?
Thank you so much.
Example code:
test <- data.frame(variables = c("PE_35", "PE_49"),
value1=c(13,3),
value2=c(75,31),
value3=c(7,17),
value4 =c(5,49))
library(reshape2) # for melt
melted <- melt(test, "variables")
melted$cO <- c("A","A","B","B","A","A","B","B")
melted$cat <- ''
melted[melted$variable == 'value1' | melted$variable == 'value2',]$cat <-
"0"
melted[melted$variable == 'value3' | melted$variable == 'value4',]$cat <-
"1"
names(melted)[3] <- "recuento"
library(ggplot2)
ggplot(melted, aes(x = cat, y = recuento,ymax=max(recuento)*1.05, fill =
cO)) +
geom_bar(stat = 'identity', position = 'stack', col="black") +
facet_grid(~ variables)+
geom_text(aes(label = recuento), size = 5, hjust = 0.5, vjust = 1,
position ="stack")
------
Aurora González Vidal
Sección Apoyo Estadístico.
Servicio de Apoyo a la Investigación (SAI).
Vicerrectorado de Investigación.
Universidad de Murcia
Edif. SACE . Campus de Espinardo.
30100 Murcia
@. aurora.gonzalez2 en um.es
T. 868 88 7315
F. 868 88 7302
www.um.es/sai
www.um.es/ae
[[alternative HTML version deleted]]
More information about the R-help
mailing list