Himno Nacional
library(syuzhet)
library(RColorBrewer)
texto_cadena <- scan(file = "/Users/ingridzapatajuarez/Downloads/R/himnonacional.txt", fileEncoding = "UTF-8", what = character(), sep = "\n", allowEscapes = T)
texto_palabras <- get_tokens(texto_cadena)
head(texto_palabras)
## [1] "mexicanos" "al" "grito" "de" "guerra" "el"
length(texto_palabras)
## [1] 496
oraciones_vector <- get_sentences(texto_cadena)
length(oraciones_vector)
## [1] 92
sentimientos_df <- get_nrc_sentiment(texto_palabras, lang="spanish")
summary(sentimientos_df)
## anger anticipation disgust fear
## Min. :0.0000 Min. :0.00000 Min. :0.00000 Min. :0.0000
## 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.:0.0000
## Median :0.0000 Median :0.00000 Median :0.00000 Median :0.0000
## Mean :0.0625 Mean :0.04234 Mean :0.02218 Mean :0.0746
## 3rd Qu.:0.0000 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.0000
## Max. :3.0000 Max. :2.00000 Max. :2.00000 Max. :2.0000
## joy sadness surprise trust
## Min. :0.00000 Min. :0.00000 Min. :0.00000 Min. :0.00000
## 1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.:0.00000
## Median :0.00000 Median :0.00000 Median :0.00000 Median :0.00000
## Mean :0.04839 Mean :0.04234 Mean :0.02621 Mean :0.04032
## 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.00000
## Max. :2.00000 Max. :2.00000 Max. :2.00000 Max. :2.00000
## negative positive
## Min. :0.00000 Min. :0.0000
## 1st Qu.:0.00000 1st Qu.:0.0000
## Median :0.00000 Median :0.0000
## Mean :0.08266 Mean :0.1008
## 3rd Qu.:0.00000 3rd Qu.:0.0000
## Max. :3.00000 Max. :3.0000
head(sentimientos_df)
## anger anticipation disgust fear joy sadness surprise trust negative positive
## 1 0 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0 0
## 3 2 0 0 1 0 1 2 0 2 0
## 4 0 0 0 0 0 0 0 0 0 0
## 5 1 0 0 2 0 1 0 0 2 0
## 6 0 0 0 0 0 0 0 0 0 0
barplot(
colSums(prop.table(sentimientos_df[,1:8])),
spce= 0.2,
horiz = FALSE,
las = 1,
cex.names = 0.7,
col = brewer.pal(n=8, name= "Set3"),
main = "Analisis de Himno Nacional Mexicano",
xlab = "emociones"
)
## Warning in plot.window(xlim, ylim, log = log, ...): "spce" is not a graphical
## parameter
## Warning in axis(if (horiz) 2 else 1, at = at.l, labels = names.arg, lty =
## axis.lty, : "spce" is not a graphical parameter
## Warning in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...): "spce"
## is not a graphical parameter
## Warning in axis(if (horiz) 1 else 2, cex.axis = cex.axis, ...): "spce" is not a
## graphical parameter
palabras_miedo <- texto_palabras[sentimientos_df$fear >0]
palabras_miedo_orden <- sort(table(unlist(palabras_miedo)), decreasing=TRUE)
head(palabras_miedo_orden, n = 10)
##
## guerra sangre golpe guerrero metralla destino dios enemigo
## 8 4 2 2 2 1 1 1
## grito impotente
## 1 1
secuencia_sentimientos <- (sentimientos_df$negative*-1) + sentimientos_df$positive
simple_plot(secuencia_sentimientos)