Dividing a chart in two parts

enter image description here

I have the code of two graphs that I want to separate into two. I would like to see half of these results on one graph and the other half on another since the current plot contains too much information. Here is the code for my charts:

    ATENCIONFUNCIONARIO <- Medellin8 %>%
      group_by(NOMBRE_SERVICIO, NOMBRE, NOMBRE_SERVICIO) %>%
      summarize(TIEMPO = mean(TIEMPO)) %>%
      ungroup() %>%
      mutate(NOMBRE_SERVICIO = factor(NOMBRE_SERVICIO, levels = unique(NOMBRE_SERVICIO)),
             NOMBRE = as.factor(NOMBRE))


  # First Chart  

    grafico5 <- ggplot(data = ATENCIONFUNCIONARIO, 
                       aes(x = NOMBRE_SERVICIO, y = TIEMPO, group = NOMBRE, colour = NOMBRE)) + 
      xlab("SERVICIO") + ylab("CANTIDAD") +
      ggtitle("TIEMPO PROMEDIO ATENCIÓN FUNCIONARIO")+
      theme(axis.text.x=element_text(angle=90,hjust=1)) +
      theme(plot.title = element_text(hjust = 0.5))+
      theme(panel.border = element_blank(), panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(), axis.line = element_line(colour = "white"))+  
      geom_line(lwd=1)
    grafico5

grafico

I would do something like this:

 grafico5 <- ATENCIONFUNCIONARIO %>%
                    mutate(grouping = NOMBRE %in% c("group1","group2","group3") %>% 
                   ggplot(aes(x = NOMBRE_SERVICIO, y = TIEMPO, group = NOMBRE, colour = NOMBRE)) + facet_wrap(~grouping) +
      xlab("SERVICIO") + ylab("CANTIDAD") +
      ggtitle("TIEMPO PROMEDIO ATENCIÓN FUNCIONARIO")+
      theme(axis.text.x=element_text(angle=90,hjust=1)) +
      theme(plot.title = element_text(hjust = 0.5))+
      theme(panel.border = element_blank(), panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(), axis.line = element_line(colour = "white"))+  
      geom_line(lwd=1)
    grafico5

The mutate function adds another variable that would read TRUE or FALSE depending on whether that particular NOMBRE was in the list. I just used "group1" and "group2" because I don't know what values are in NOMBRE. The facet_wrap would create two graphs. One for NOMBRE's that are in the list and one for those that aren't.

I need to compare all the names, for this reason I can't divide in groups.
I need to divide the chart in to parts sometime like that:

p8 <- p7 + scale_x_discrete(breaks = DEMANDADIATRAMITE1$NOMBRE_SERVICIO[1:20]) + coord_cartesian(xlim = c(1, 20))
p10 <- p7 + scale_x_discrete(breaks = DEMANDADIATRAMITE1$NOMBRE_SERVICIO[21:50]) + coord_cartesian(xlim = c(21, 50))
p8

But this code don't run in this case.

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Just in case, this is the Spanish version of the guide

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.