2

necesito su ayuda eliminando de esta gráfica la leyenda del eje Y2 (Cumulative Percentage):

He intentado resolver esto colocando el código Y2lab("") pero esto no me arregla el problema.

[![UNICOS2 <- aggregate(ID_GESTION_ATENCION ~ NOMBRE_SERVICIO, Atencion4, function(x) length(unique(x)))
UNICOS2 <- UNICOS2\[order(-UNICOS2$ID_GESTION_ATENCION), \]
UNICOS2$NOMBRE_SERVICIO <- factor(UNICOS2$NOMBRE_SERVICIO, levels=UNICOS2$NOMBRE_SERVICIO, ordered = TRUE)

## PARETO_TIPO_DE-SERVICIO

# creamos el gráfico base
ggplot(UNICOS2 , aes(x = NOMBRE_SERVICIO, y = ID_GESTION_ATENCION)) + 
  geom_bar(stat="identity") +
  theme(axis.text.x=element_text(angle=90,hjust=1)) + 
  stat_pareto(point.color = "DIMGRAY",   
              point.size = 2,        
              line.color = "black",  
              bars.fill = "#FF7F50")+
  ggtitle("Pareto Tipo Servicio RMA")+
  theme(plot.title = element_text(hjust = 0.5)) +
  ylab("Cantidad") +
  y2lab("Porcentaje Acumulado")
  xlab("") +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "gray")) -> p7

# Armamos las dos graficas
p8 <- p7 + scale_x_discrete(breaks = UNICOS2$NOMBRE_SERVICIO\[1:12\]) + coord_cartesian(xlim = c(1, 12))
p8][1]][1]

1 respuesta 1

0

Lamentablemente stat_pareto() no se integra del todo bien con ggplot(), no hay forma de "customizar" esa etiqueta tal como lo haríamos normalmente. Esto por que stat_pareto() configura este dato de manera "dura", revisando el código de la función vemos:

SEC.scaleY <- ggplot2::scale_y_continuous(sec.axis = ggplot2::sec_axis(~./(max(.) * 
              0.95) * 100, name = "Cumulative Percentage"))

La alternativa más simple, es reescribir el código anterior, es decir, algo así:

scale_y_continuous(sec.axis = sec_axis(~./(max(.) * 0.95) * 100, name = ""))

Mantenemos la formula original, y solo reemplazamos el texto de la etiqueta con name = "". Luego, lo agregas a tu código luego del stat_pareto():

ggplot(UNICOS2 , aes(x = NOMBRE_SERVICIO, y = ID_GESTION_ATENCION)) + 
  geom_bar(stat="identity") +
  theme(axis.text.x=element_text(angle=90,hjust=1)) + 
  stat_pareto(point.color = "DIMGRAY",   
              point.size = 2,        
              line.color = "black",  
              bars.fill = "#FF7F50")+
  ggtitle("Pareto Tipo Servicio RMA")+
  theme(plot.title = element_text(hjust = 0.5)) +
  ylab("Cantidad") +
  xlab("") +
  scale_y_continuous(sec.axis = sec_axis(~./(max(.) * 0.95) * 100, name = ""))  +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "gray")) -> p7

Nota: Esto emitirá un "warning" del cual no deberíamos preocuparnos:

Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.

1
  • Mil gracias, ya quedo solucionado el 30 ago. 2019 a las 17:11

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.