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
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 repr oducible ex ample (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
Just in case, this is the Spanish version of the guide
Un ejemplo mínimo reproducible consiste de los siguientes puntos:
Un conjunto de datos mínimo que permita reproducir el problema.
El mínimo código ejecutable necesario para reproducir el problema, que pueda
ser ejecutado con el conjunto de datos brindado y que incluya la
información necesaria sobre los paquetes utilizados.
Vayamos rápidamente sobre cada uno de estos puntos con ejemplos:
Conjunto de Datos Mínimo (Datos de Muestra)
Usted necesita proporcionar un conjunto de datos que sea lo suficientemente pequeño para ser pegado (razonablemente) en una publicación, pero lo suficientemente grande para reproducir el problema.
Digamos, a manera de ejemplo, que usted está trabajando con el…
system
Closed
September 12, 2019, 3:53pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.