Si quieres que te quede centrado el valor dentro de cada casilla
tabla.barras<-ddply(tabla.barras,.(Rangos), transform, Pos = ave(Asistentes,  FUN = cumsum) - Asistentes / 2)
ggplot(tabla.barras, aes(x = Rangos, y = Asistentes, Â group = Rangos, fill = Clase)) + Â Â geom_bar(stat= "identity")+Â
 geom_text(aes(label = Asistentes,y=Pos), size = 3) +  labs(title = "Asistentes por tipo de servicio según tramo de edad."    , subtitle = subtit.todos    , x = "", y = "Cantidad de asistentes" ) +    # , caption = caption) + theme(legend.position = "bottom", legend.direction = "horizontal", legend.title = element_blank()) + guides(fill = guide_legend(nrow = 1), color = guide_legend(nrow = 1), size = 3)
El Lunes 26 de junio de 2017 12:43, Mauricio Monsalvo <m.monsalvo en gmail.com> escribió:
Bingo!! Muchas gracias, José Luis!
El 26 de junio de 2017, 7:13, jose luis <pepeceb en yahoo.es> escribió:
Y asi? Usando group = Rangos, fill = Clase
ggplot(tabla.barras, aes(x = Rangos, y = Asistentes, Â group = Rangos, fill = Clase)) + Â Â geom_col(position = "stack")
El Lunes 26 de junio de 2017 11:39, Mauricio Monsalvo <m.monsalvo en gmail.com> escribió:
Muchas gracias a los dos por las respuestas. Estoy usando tidiverse, que debe ser la del conflicto. Pero probé reseteando el R y corriendo la sintaxis de Carlos sola y tampoco funciona...   library(tidyverse)Loading tidyverse: ggplot2Loading tidyverse: tibbleLoading tidyverse: tidyrLoading tidyverse: readrLoading tidyverse: purrrLoading tidyverse: dplyrConflicts with tidy packages ------------------------------ ------------------------------ --------------------------filter(): dplyr, statslag():   dplyr, statsWarning messages:1: package ?tidyverse? was built under R version 3.3.3 2: package ?tibble? was built under R version 3.3.3 3: package ?tidyr? was built under R version 3.3.3 4: package ?readr? was built under R version 3.3.3 5: package ?purrr? was built under R version 3.3.3 Los datos de la sesión son los siguientes (Imagino que tengo que actualizar el propio R tambbién):> sessionInfo()R version 3.3.2 (2016-10-31)Platform: x86_64-w64-mingw32/x64 (64-bit)Running under: Windows >= 8 x64 (build 9200)
locale:[1] LC_COLLATE=Spanish_Argentina. 1252 Â LC_CTYPE=Spanish_Argentina. 1252 Â Â LC_MONETARY=Spanish_ Argentina.1252[4] LC_NUMERIC=C Â Â Â Â Â Â Â Â Â Â Â LC_TIME=Spanish_Argentina.1252 Â Â
attached base packages:[1] stats   graphics  grDevices utils   datasets  methods  base   Â
other attached packages:Â [1] openxlsx_4.0.17 Â stringr_1.2.0 Â Â data.table_1.10.4 foreign_0.8-67 Â Â dplyr_0.5.0 Â Â Â purrr_0.2.2.2 Â Â Â [7] readr_1.1.1 Â Â Â tidyr_0.6.3 Â Â Â tibble_1.3.3 Â Â Â ggplot2_2.2.1 Â Â tidyverse_1.1.1 Â
loaded via a namespace (and not attached):Â [1] Rcpp_0.12.11 Â Â cellranger_1.1.0 plyr_1.8.4 Â Â Â forcats_0.2.0 Â Â tools_3.3.2 Â Â Â jsonlite_1.5 Â Â Â [7] lubridate_1.6.0 Â gtable_0.2.0 Â Â nlme_3.1-128 Â Â lattice_0.20-35 Â rlang_0.1.1 Â Â Â psych_1.7.5 Â Â Â [13] DBI_0.6-1 Â Â Â Â parallel_3.3.2 Â haven_1.0.0 Â Â Â httr_1.2.1 Â Â Â xml2_1.1.1 Â Â Â hms_0.3 Â Â Â Â Â [19] grid_3.3.2 Â Â Â R6_2.2.1 Â Â Â Â readxl_1.0.0 Â Â reshape2_1.4.2 Â modelr_0.1.0 Â Â magrittr_1.5 Â Â [25] scales_0.4.1 Â Â assertthat_0.2.0 mnormt_1.5-5 Â Â rvest_0.3.2 Â Â Â colorspace_1.3-2 stringi_1.1.5 Â Â [31] lazyeval_0.2.0 Â munsell_0.4.3 Â Â broom_0.4.2 Â Â
El 25 de junio de 2017, 5:26, Carlos Ortega <cof en qualityexcellence.es> escribió:
Hola,
Mira la versión de ggplot2 que estás usando por tenerla actualizada a la última...A mi me funciona introduciendo algún cambio  salvo la última lÃnea cuando cambias el tema...
#-----------
Lines <- " id  Rangos  Clase Asistentes1  45d   EPI     4052   1a   EPI     8123   2a   EPI    16394   3a   EPI    22025   4a   EPI    19946   5a   EPI     2557  45d SemiEPI     6148   1a SemiEPI     8819   2a SemiEPI    217410  3a SemiEPI    325411  4a SemiEPI    293412  5a SemiEPI     66213  45d  NoEPI     56514  1a  NoEPI     31615  2a  NoEPI     61516  3a  NoEPI     95617  4a  NoEPI     84018  5a  NoEPI     609"
DF <- read.table(textConnection( Lines), header=T, as.is = TRUE)tabla.barras <- DFtabla.barras$Clase2 <- factor(tabla.barras$Clase, levels=c("EPI", "SemiEPI", "NoEPI"))
library(ggplot2)
subtit.todos <- "Todos los Espacios (N = 311)."caption <- 'FLACSO - UNICEF - SENAF (2017)'ggplot(tabla.barras, aes(x = Rangos, y = Asistentes,  group = Clase2, fill = Clase2)) +   geom_col(position = "stack") + geom_text(aes(label = Asistentes), position = position_stack(), vjust = 1, size = 4) +  labs(title = "Asistentes por tipo de servicio según tramo de edad."    , subtitle = subtit.todos    , x = "", y = "Cantidad de asistentes" ) +    # , caption = caption) + theme(legend.position = "bottom", legend.direction = "horizontal", legend.title = element_blank()) + guides(fill = guide_legend(nrow = 1), color = guide_legend(nrow = 1), size = 3)Â
#-----------
Saludos,Carlos Ortegawww.qualityexcellence.es
El 25 de junio de 2017, 10:19, jose luis via R-help-es <r-help-es en r-project.org> escribió:
Es curioso porque aplicando tu script me queda como tu quieres que te quede a ti no? No he hecho nada que no hayas hecho tu
ggplot(tabla.barras, aes(x = Rangos, y = Asistentes, fill = Clase)) +     geom_bar(stat = "identity", position = "stack") +   geom_text(aes(label = Asistentes), position = position_stack(), vjust = 1, size = 4) +    labs(title = "Asistentes por tipo de servicio según tramo de edad."     , subtitle = subtit.todos     , x = "", y = "Cantidad de asistentes"     , caption = caption)
El Sábado 24 de junio de 2017 23:07, Mauricio Monsalvo <m.monsalvo en gmail.com> escribió:
??Hola. Estoy intentando ordenar el gráfico tal que las columnas se apilen en el siguiente orden: debajo, los EPI; los SemiEPI en el medio y los NoEpi arriba de todo.Estos son mis datos:
▾ Quoted text (1 line)
tabla.barras  Rangos  Clase Asistentes1  De 45d   EPI     4052  De 1a   EPI     8123  De 2a   EPI    16394  De 3a   EPI    22025  De 4a   EPI    19946  De 5a   EPI     2557  De 45d SemiEPI     6148  De 1a SemiEPI     8819  De 2a SemiEPI    217410  De 3a SemiEPI    325411  De 4a SemiEPI    293412  De 5a SemiEPI     66213 De 45d  NoEPI     56514  De 1a  NoEPI     31615  De 2a  NoEPI     61516  De 3a  NoEPI     95617  De 4a  NoEPI     84018  De 5a  NoEPI     609?Probé cambiando el orden en el factor, pero no altera el orden en el gráfico:??tabla.barras$Clase <- as.factor(tabla.barras$Clase)factor(tabla.barras$Clase, levels=c("EPI", "SemiEPI", "NoEPI"))Ni:ordered(tabla.barras$Clase, levels=c("EPI", "SemiEPI", "NoEPI"))Tampoco parece alterarlo el ordenar la tabla como:
tabla.barras[order(Clase)] # ni -ClaseEstoy seguro que el orden en el ggplot2 lo pone el orden que trae la tabla con los datos, pero estoy perdido por los resultados.subtit.todos <- "Todos los Espacios (N = 311)."caption <- 'FLACSO - UNICEF - SENAF (2017)'ggplot(tabla.barras, aes(x = Rangos, y = Asistentes, fill = Clase)) + #Â
   geom_bar(stat = "identity", position = "stack") +   geom_text(aes(label = Asistentes), position = position_stack(), vjust = 1, size = 4) +    labs(title = "Asistentes por tipo de servicio según tramo de edad."     , subtitle = subtit.todos     , x = "", y = "Cantidad de asistentes"     , caption = caption) +   theme(legend.position = "bottom", legend.direction = "vertical", legend.title = element_blank()) +   guides(fill = guide_legend(nrow = 1), color = guide_legend(nrow = 1), size = 3) +    theme(plot.caption = element_text(size = 8, hjust = 0, margin = margin(t = 15)))?
?--Â
Mauricio______________________________ _________________
R-help-es mailing list
R-help-es en r-project.org
https://stat.ethz.ch/mailman/l istinfo/r-help-es
______________________________ _________________
R-help-es mailing list
R-help-es en r-project.org
https://stat.ethz.ch/mailman/l istinfo/r-help-es
--
Saludos,
Carlos Ortega
www.qualityexcellence.es
--
Mauricio______________________________ _________________
R-help-es mailing list
R-help-es en r-project.org
https://stat.ethz.ch/mailman/ listinfo/r-help-es