Graficos Descriptivos
datos2<-read_excel("Data2.xlsx")
#1. Grafico Lugar de consumo
List of 92
$ line : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ rect : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ text :List of 11
..$ family : chr ""
..$ face : chr "plain"
..$ colour : chr "black"
..$ size : num 11
..$ hjust : num 0.5
..$ vjust : num 0.5
..$ angle : num 0
..$ lineheight : num 0.9
..$ margin : 'margin' num [1:4] 0points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ title : NULL
$ aspect.ratio : NULL
$ axis.title : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ axis.title.x : NULL
$ axis.title.x.top : NULL
$ axis.title.x.bottom : NULL
$ axis.title.y : NULL
$ axis.title.y.left : NULL
$ axis.title.y.right : NULL
$ axis.text : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ axis.text.x : NULL
$ axis.text.x.top : NULL
$ axis.text.x.bottom : NULL
$ axis.text.y : NULL
$ axis.text.y.left : NULL
$ axis.text.y.right : NULL
$ axis.ticks : NULL
$ axis.ticks.x : NULL
$ axis.ticks.x.top : NULL
$ axis.ticks.x.bottom : NULL
$ axis.ticks.y : NULL
$ axis.ticks.y.left : NULL
$ axis.ticks.y.right : NULL
$ axis.ticks.length : 'simpleUnit' num 0points
..- attr(*, "unit")= int 8
$ axis.ticks.length.x : NULL
$ axis.ticks.length.x.top : NULL
$ axis.ticks.length.x.bottom: NULL
$ axis.ticks.length.y : NULL
$ axis.ticks.length.y.left : NULL
$ axis.ticks.length.y.right : NULL
$ axis.line : NULL
$ axis.line.x : NULL
$ axis.line.x.top : NULL
$ axis.line.x.bottom : NULL
$ axis.line.y : NULL
$ axis.line.y.left : NULL
$ axis.line.y.right : NULL
$ legend.background : NULL
$ legend.margin : NULL
$ legend.spacing : NULL
$ legend.spacing.x : NULL
$ legend.spacing.y : NULL
$ legend.key : NULL
$ legend.key.size : 'simpleUnit' num 1.2lines
..- attr(*, "unit")= int 3
$ legend.key.height : NULL
$ legend.key.width : NULL
$ legend.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ legend.text.align : NULL
$ legend.title :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ legend.title.align : NULL
$ legend.position : chr "right"
$ legend.direction : NULL
$ legend.justification : NULL
$ legend.box : NULL
$ legend.box.just : NULL
$ legend.box.margin : NULL
$ legend.box.background : NULL
$ legend.box.spacing : NULL
$ panel.background : NULL
$ panel.border : NULL
$ panel.spacing : 'simpleUnit' num 5.5points
..- attr(*, "unit")= int 8
$ panel.spacing.x : NULL
$ panel.spacing.y : NULL
$ panel.grid : NULL
$ panel.grid.major : NULL
$ panel.grid.minor : NULL
$ panel.grid.major.x : NULL
$ panel.grid.major.y : NULL
$ panel.grid.minor.x : NULL
$ panel.grid.minor.y : NULL
$ panel.ontop : logi FALSE
$ plot.background : NULL
$ plot.title :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 1.2
..$ hjust : num 0
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 5.5points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.title.position : chr "panel"
$ plot.subtitle :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 5.5points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.caption :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 0.8
..$ hjust : num 1
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 5.5points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.caption.position : chr "panel"
$ plot.tag :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 1.2
..$ hjust : num 0.5
..$ vjust : num 0.5
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.tag.position : chr "topleft"
$ plot.margin : 'simpleUnit' num [1:4] 0lines 0lines 0lines 0lines
..- attr(*, "unit")= int 3
$ strip.background : NULL
$ strip.background.x : NULL
$ strip.background.y : NULL
$ strip.placement : NULL
$ strip.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ strip.text.x : NULL
$ strip.text.y : NULL
$ strip.switch.pad.grid : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
$ strip.switch.pad.wrap : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
- attr(*, "class")= chr [1:2] "theme" "gg"
- attr(*, "complete")= logi TRUE
- attr(*, "validate")= logi TRUE
#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")
[1] "de" "la" "que" "el"
[5] "en" "y" "a" "los"
[9] "del" "se" "las" "por"
[13] "un" "para" "con" "no"
[17] "una" "su" "al" "lo"
[21] "como" "más" "pero" "sus"
[25] "le" "ya" "o" "este"
[29] "sí" "porque" "esta" "entre"
[33] "cuando" "muy" "sin" "sobre"
[37] "también" "me" "hasta" "hay"
[41] "donde" "quien" "desde" "todo"
[45] "nos" "durante" "todos" "uno"
[49] "les" "ni" "contra" "otros"
[53] "ese" "eso" "ante" "ellos"
[57] "e" "esto" "mí" "antes"
[61] "algunos" "qué" "unos" "yo"
[65] "otro" "otras" "otra" "él"
[69] "tanto" "esa" "estos" "mucho"
[73] "quienes" "nada" "muchos" "cual"
[77] "poco" "ella" "estar" "estas"
[81] "algunas" "algo" "nosotros" "mi"
[85] "mis" "tú" "te" "ti"
[89] "tu" "tus" "ellas" "nosotras"
[93] "vosotros" "vosotras" "os" "mío"
[97] "mía" "míos" "mías" "tuyo"
[101] "tuya" "tuyos" "tuyas" "suyo"
[105] "suya" "suyos" "suyas" "nuestro"
[109] "nuestra" "nuestros" "nuestras" "vuestro"
[113] "vuestra" "vuestros" "vuestras" "esos"
[117] "esas" "estoy" "estás" "está"
[121] "estamos" "estáis" "están" "esté"
[125] "estés" "estemos" "estéis" "estén"
[129] "estaré" "estarás" "estará" "estaremos"
[133] "estaréis" "estarán" "estaría" "estarías"
[137] "estaríamos" "estaríais" "estarían" "estaba"
[141] "estabas" "estábamos" "estabais" "estaban"
[145] "estuve" "estuviste" "estuvo" "estuvimos"
[149] "estuvisteis" "estuvieron" "estuviera" "estuvieras"
[153] "estuviéramos" "estuvierais" "estuvieran" "estuviese"
[157] "estuvieses" "estuviésemos" "estuvieseis" "estuviesen"
[161] "estando" "estado" "estada" "estados"
[165] "estadas" "estad" "he" "has"
[169] "ha" "hemos" "habéis" "han"
[173] "haya" "hayas" "hayamos" "hayáis"
[177] "hayan" "habré" "habrás" "habrá"
[181] "habremos" "habréis" "habrán" "habría"
[185] "habrías" "habríamos" "habríais" "habrían"
[189] "había" "habías" "habíamos" "habíais"
[193] "habían" "hube" "hubiste" "hubo"
[197] "hubimos" "hubisteis" "hubieron" "hubiera"
[201] "hubieras" "hubiéramos" "hubierais" "hubieran"
[205] "hubiese" "hubieses" "hubiésemos" "hubieseis"
[209] "hubiesen" "habiendo" "habido" "habida"
[213] "habidos" "habidas" "soy" "eres"
[217] "es" "somos" "sois" "son"
[221] "sea" "seas" "seamos" "seáis"
[225] "sean" "seré" "serás" "será"
[229] "seremos" "seréis" "serán" "sería"
[233] "serías" "seríamos" "seríais" "serían"
[237] "era" "eras" "éramos" "erais"
[241] "eran" "fui" "fuiste" "fue"
[245] "fuimos" "fuisteis" "fueron" "fuera"
[249] "fueras" "fuéramos" "fuerais" "fueran"
[253] "fuese" "fueses" "fuésemos" "fueseis"
[257] "fuesen" "siendo" "sido" "tengo"
[261] "tienes" "tiene" "tenemos" "tenéis"
[265] "tienen" "tenga" "tengas" "tengamos"
[269] "tengáis" "tengan" "tendré" "tendrás"
[273] "tendrá" "tendremos" "tendréis" "tendrán"
[277] "tendría" "tendrías" "tendríamos" "tendríais"
[281] "tendrían" "tenía" "tenías" "teníamos"
[285] "teníais" "tenían" "tuve" "tuviste"
[289] "tuvo" "tuvimos" "tuvisteis" "tuvieron"
[293] "tuviera" "tuvieras" "tuviéramos" "tuvierais"
[297] "tuvieran" "tuviese" "tuvieses" "tuviésemos"
[301] "tuvieseis" "tuviesen" "teniendo" "tenido"
[305] "tenida" "tenidos" "tenidas" "tened"
#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"))
#2. Grafico de Turnos
"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"
G2<-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")
G2
"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_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"
G3<-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="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 MOTIVO")
G3
#4. Grafico del Motivo segun Lugar
"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"
G4<-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=4.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")
G4
"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"
G5<-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=4.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")
G5
set.seed(2)
par(mfrow = c(1, 2))
y1 <- datos2$Canti_gene
y2 <- datos2$Cant_consu
G6<-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")
)
G6
G7<-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")
)
G7
G6 + G7
Tabla_6 <- datos2 %>% group_by(Motivo,LUGAR,TURNO) %>%
summarise(prom_can_consu=mean(Cant_consu))
G8<-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")
G8
set.seed(6)
par(mfrow = c(1, 2))
G9<- ggplot(Tabla_6, aes(x=prom_can_consu, fill=Motivo))+
geom_density(alpha=0.4)+
xlab("Promedio de Cantidad Consumida")+
ylab("Densidad")+
ggtitle("DISTRIBUCIÓN DE LA CANTIDAD CONSUMIDA (kg) SEGÚN EL MOTIVO")
G9
G10<- ggplot(Tabla_6, aes(x=prom_can_consu, fill=LUGAR))+
geom_density(alpha=0.4)+
xlab("Promedio de Cantidad Consumida")+
ylab("Densidad")+
ggtitle("DISTRIBUCIÓN DE LA CANTIDAD GENERADA (kg) SEGÚN EL MOTIVO")
G10
G11<- ggplot(Tabla_6, aes(x=prom_can_consu, fill=TURNO))+
geom_density(alpha=0.4)+
xlab("Promedio de Cantidad Consumida")+
ylab("Densidad")+
ggtitle("DISTRIBUCIÓN DE LA CANTIDAD CONSUMIDA (kg) SEGÚN EL MOTIVO")
G11
G9 + G10 +G11