Graficos Descriptivos
datos2<-read_excel("Data2.xlsx")
#Transformación de los datos para grafica #1
Tabla_1<-datos2 %>%
group_by(LUGAR) %>% # Variable a ser transformada
count() %>%
ungroup() %>%
mutate(PORCENTAJES = `n` / sum(`n`)) %>%
arrange(PORCENTAJES) %>%
mutate(etiquetas = scales::percent(PORCENTAJES))
#Grafico #1
G1<-ggplot(Tabla_1, aes(x = "", y = PORCENTAJES, fill = LUGAR)) +
geom_col(color = "black") +
geom_label(aes(label = etiquetas),
position = position_stack(vjust = 0.5),
show.legend = FALSE) +
guides(fill = guide_legend(title = "LUGAR")) + scale_color_viridis_c() +
coord_polar(theta = "y") + ggtitle ("DISTRIBUCIÓN SEGÚN SU LUGAR DE CONSUMO")
#theme_void()
G1
#cargamos las librerias correspondientes
library(tm)
library(NLP)
library(SnowballC)
library(RColorBrewer)
library(wordcloud)
#Que palabras hay con mayor frecuencia en los comentarios para .....
#nuestro texto lo guardamos en bloc de notas en formato txt
texto <- readLines("DESCRIPCION.txt")
texto = iconv(texto, to="ASCII//TRANSLIT")
texto = Corpus(VectorSource(texto))
########### LIMPIAMOS NUESTRO TEXTO CON EL COMANDO tm_map
#ponemos todos los datos a minuscula (A!=a)
discurso=tm_map(texto, tolower)
#quitamos los espacios en blanco
discurso =tm_map(discurso, stripWhitespace)
#quitamos la puntuacion
discurso = tm_map(discurso, removePunctuation)
#quitamos los numeros
discurso = tm_map(discurso, removeNumbers)
#mostramos palabras vacias y genericas
#stopwords("spanish")
#quitamos palabras genericas
discurso=tm_map(discurso, removeWords,stopwords("spanish"))
#tambien podemos tener nuestra propia lista de palabras a quitar
############### DATA FRAME DE PALABRAS CON SU FRECUENCIA
#Creamos matriz de letras
letras= TermDocumentMatrix(discurso)
findFreqTerms(letras, lowfreq=5)
[1] "azul" "estandar" "floral" "maxi"
[5] "bicarbonato" "economico" "enzimatico" "limon"
[9] "verbena" "blanco" "super" "verde"
[13] "preten" "premium" "ptos" "rosados"
[17] "plus" "lavanda" "det" "est"
[21] "flo" "granel" "bla" "pre"
[25] "naranja" "member" "selection" "pot"
[29] "den" "deter" "eco" "antib"
[33] "lim" "aloe" "alg" "ver"
[37] "act" "activos" "oxigenos" "economio"
[41] "rosadas" "exp"
matrix=as.matrix(letras)
#lo ordenamos y sumamos las letras de nuestra matriz
vector <- sort(rowSums(matrix),decreasing=TRUE)
#creamos la data con las palabras y su frecuencia
dataletras <- data.frame(word= names(vector),frequencia=vector)
# lo nombra y le da formato de data.frame
############ GRAFICAMOS LA NUBE DE PALABRAS
#wordcloud(words = dataletras$word, freq = dataletras$freq, min.freq = 1,
# max.words=100000)
#en el centro la palabra mas importante,
wordcloud(words = dataletras$word, freq = dataletras$freq, min.freq = 1,
max.words=100000, random.order=FALSE, rot.per=0.2,
colors=brewer.pal(8, "Set1"))
"Creación de tabla de frecuencia para hacer el grafico con fr y porcentaje"
[1] "Creación de tabla de frecuencia para hacer el grafico con fr y porcentaje"
Tabla_2 <- datos2 %>%
dplyr::group_by(TURNO) %>%
dplyr::summarise(Total = n()) %>%
dplyr::mutate(Porcentaje = round(Total/sum(Total)*100, 1)) %>%
dplyr::arrange(TURNO)
"Grafico"
[1] "Grafico"
G3<-ggplot(Tabla_2, aes(x =TURNO, y=Total) ) +
geom_bar(width = 0.9,stat="identity",
position = position_dodge(), fill="red3") +
ylim(c(0,1100))+
#xlim(c(0,300)) +
#ggtitle("Un título") +
labs(x="TURNO", y= "Frecuencias \n (Porcentajes)") +
geom_text(aes(label=paste0(Total," ", "", "(", Porcentaje, "%", ")")),
vjust=-0.9,
color="black",
hjust=0.5,
# define text position and size
position = position_dodge(0.9),
angle=0,
size=4.0) +
theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1)) +
theme_bw(base_size = 14) +
#coord_flip() +
facet_wrap(~"DISTRIBUCIÓN SEGÚN EL TURNO")
G3
"Creación de tabla de cruzada para hacer el grafico con fr y porcentaje"
[1] "Creación de tabla de cruzada para hacer el grafico con fr y porcentaje"
Tabla_3 <- datos2 %>%
dplyr::group_by(Motivo) %>%
dplyr::summarise(Total = n()) %>%
dplyr::mutate(Porcentaje = round(Total/sum(Total)*100, 1)) %>%
dplyr::arrange(Motivo)
"Grafico"
[1] "Grafico"
G4<-ggplot(Tabla_3, aes(x =Motivo, y=Total) ) +
geom_bar(width = 0.9,stat="identity",
position = position_dodge(), fill="yellow3") +
ylim(c(0,1850))+
#xlim(c(0,300)) +
#ggtitle("Un título") +
labs(x="MOTIVO", y= "Frecuencias \n (Porcentajes)") +
geom_text(aes(label=paste0(Total," ", "", "(", Porcentaje, "%", ")")),
vjust=-0.9,
color="black",
hjust=0.5,
# define text position and size
position = position_dodge(0.9),
angle=0,
size=5.0) +
theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1)) +
theme_bw(base_size = 14) +
#coord_flip() +
facet_wrap(~"DISTRIBUCIÓN SEGÚN EL MOTIVO")
G4
"Creación de Tabla Cruzada"
[1] "Creación de Tabla Cruzada"
Tabla4 <- datos2 %>%
dplyr::group_by(Motivo, LUGAR) %>%
dplyr::summarise(Total = n()) %>%
dplyr::mutate(Porcentaje = round(Total/sum(Total)*100, 1)) %>%
dplyr::arrange(Motivo)
"Grafico"
[1] "Grafico"
G5<-ggplot(Tabla4, aes(x = Motivo, y=Total, fill=LUGAR) ) +
geom_bar(width = 0.9,stat="identity",
position = position_dodge()) +
ylim(c(0,80))+
#xlim(c(0,300)) +
#ggtitle("Un título") +
labs(x="", y= "Frecuencias \n (Porcentajes)") +
labs(fill = "LUGAR") +
scale_fill_manual(values = c("pink", "skyblue")) +
geom_text(aes(label=paste0(Total," ", "", "(", Porcentaje, "%", ")")),
vjust=-0.9,
color="black",
hjust=-0.5,
# define text position and size
position = position_dodge(0.9),
angle=0,
size=6.0)+
scale_fill_discrete(name = "LUGAR", labels = c("PREPARADOR ", "TK DISOLUCION")) +
theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1)) +
theme_bw(base_size = 14) +
coord_flip() +
facet_wrap(~"DISTRIBUCIÓN DEL MOTIVO SEGÚN EL LUGAR DE CONSUMO")
G5
"Creación de Tabla Cruzada"
[1] "Creación de Tabla Cruzada"
Tabla5 <- datos2 %>%
dplyr::group_by(TURNO, LUGAR) %>%
dplyr::summarise(Total = n()) %>%
dplyr::mutate(Porcentaje = round(Total/sum(Total)*100, 1)) %>%
dplyr::arrange(TURNO)
"Grafico"
[1] "Grafico"
G6<-ggplot(Tabla5, aes(x = TURNO, y=Total, fill=LUGAR) ) +
geom_bar(width = 0.9,stat="identity",
position = position_dodge()) +
ylim(c(0,1010))+
#xlim(c(0,300)) +
#ggtitle("Un título") +
labs(x="", y= "Frecuencias \n (Porcentajes)") +
labs(fill = "Sexo") +
scale_fill_manual(values = c("cyan", "red2")) +
geom_text(aes(label=paste0(Total," ", "", "(", Porcentaje, "%", ")")),
vjust=-0.9,
color="black",
hjust=0.5,
# define text position and size
position = position_dodge(0.9),
angle=0,
size=5.0)+
scale_fill_discrete(name = "LUGAR", labels = c("PREPARADOR ", "TK DISOLUCION")) +
theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1)) +
theme_bw(base_size = 14) +
#coord_flip() +
facet_wrap(~"DISTRIBUCIÓN DEL TURNO SEGÚN EL LUGAR DE CONSUMO")
G6
set.seed(2)
par(mfrow = c(1, 2))
y1 <- datos2$Canti_gene
y2 <- datos2$Cant_consu
G7<-ggplot(datos2, aes(y = y1)) +
stat_boxplot(geom = "errorbar",
width = 0.15,
color = 1) + # Color barras error
geom_boxplot(fill = 3, # Color caja
alpha = 0.5, # Transparencia
color = 1, # Color del borde
outlier.colour = 2) +# Color atípicos
ggtitle("CANTIDAD GENERADA") +
xlab("") + ylab("kg") +theme(
plot.title = element_text(color="black", size=14, face="bold"),
axis.title.x = element_text(color="blue", size=10, face="bold"),
axis.title.y = element_text(color="black", size=10, face="bold")
)
G8<-ggplot(datos2, aes(y = y2)) +
stat_boxplot(geom = "errorbar",
width = 0.15,
color = 1) + # Color barras error
geom_boxplot(fill = 4, # Color caja
alpha = 0.5, # Transparencia
color = 1, # Color del borde
outlier.colour = 2) +# Color atípicos
ggtitle("CANTIDAD CONSUMIDA") +
xlab("") + ylab("(kg)") +theme(
plot.title = element_text(color="black", size=14, face="bold"),
axis.title.x = element_text(color="blue", size=14, face="bold"),
axis.title.y = element_text(color="black", size=14, face="bold")
)
Tabla_6 <- datos2 %>% group_by(Motivo,LUGAR,TURNO) %>%
summarise(prom_can_consu=mean(Cant_consu))
G9<-ggplot(Tabla_6, aes(x=TURNO,y=prom_can_consu, color=Motivo))+
geom_point(cex=5)+
facet_grid(cols = vars(LUGAR))+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
xlab("TURNO")+
ylab("Promedio(kg)")+
ggtitle("CANTIDAD PROMEDIO CONSUMIDA (kg) SEGÚN TURNO-LUGAR-MOTIVO")
G9
G10
G11
G12