El análisis de sentimientos o minería de opinión, es utilizado para extraer de forma automática información sobre la connotación positiva o negativa del lenguaje de un documento.
El análisis mostrará el resultado en 8 emociones básicas y 2 sentimientos
1.Alegría (joy)
2.Tristeza (sadness)
3.Ira (anger)
4.Sorpresa (surprise)
5.Asco (disgust)
6. Miedo (fear)
7.Anticipación (anticipation)
8.Confianza (trust)
Sentimientos:
1.Positivo (positive)
2.Negativo (negative)
# install.packages("syuzhet")
# install.packages("RColorBrewer")
library(syuzhet)
library(RColorBrewer)
texto_cadena <-read.delim("C:\\Users\\luisa\\Documents\\R LUISA\\MODULO 4\\triste.txt",header=FALSE)
#View(texto_cadena)
## [1] "c" "qué" "triste" "fue" "decirnos" "adiós"
## [1] 183
sentimientos_df <- get_nrc_sentiment(texto_palabras,language="spanish")
#Idiomas disponibles: Spanish, English, French, German, Italian, Portuguese, entre otros.
summary(sentimientos_df)
## anger anticipation disgust fear
## Min. :0.00000 Min. :0 Min. :0.00000 Min. :0.0000
## 1st Qu.:0.00000 1st Qu.:0 1st Qu.:0.00000 1st Qu.:0.0000
## Median :0.00000 Median :0 Median :0.00000 Median :0.0000
## Mean :0.02186 Mean :0 Mean :0.03825 Mean :0.0765
## 3rd Qu.:0.00000 3rd Qu.:0 3rd Qu.:0.00000 3rd Qu.:0.0000
## Max. :1.00000 Max. :0 Max. :1.00000 Max. :2.0000
## joy sadness surprise trust negative
## Min. :0.00000 Min. :0.0000 Min. :0 Min. :0 Min. :0.0000
## 1st Qu.:0.00000 1st Qu.:0.0000 1st Qu.:0 1st Qu.:0 1st Qu.:0.0000
## Median :0.00000 Median :0.0000 Median :0 Median :0 Median :0.0000
## Mean :0.03279 Mean :0.2077 Mean :0 Mean :0 Mean :0.1967
## 3rd Qu.:0.00000 3rd Qu.:0.0000 3rd Qu.:0 3rd Qu.:0 3rd Qu.:0.0000
## Max. :1.00000 Max. :7.0000 Max. :0 Max. :0 Max. :7.0000
## positive
## Min. :0.00000
## 1st Qu.:0.00000
## Median :0.00000
## Mean :0.04372
## 3rd Qu.:0.00000
## Max. :1.00000
## 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 1 0 1 2 0 5 0 0 5 0
## 4 0 0 0 0 0 0 0 0 0 0
## 5 0 0 0 0 0 0 0 0 0 0
## 6 0 0 0 0 0 0 0 0 0 0
barplot(
colSums(prop.table(sentimientos_df[1:8])),
space= 0.2,
horiz= FALSE,
las =1,
cex.names = 0.7,
col= brewer.pal(n=8,name="Set3"),
main= "ANÁLISIS DE SENTIMIENTOS DE LA CANCIÓN EL TRISTE",
xlab= "EMOCIONES"
)
palabras_tristeza <- texto_palabras[sentimientos_df$sadness>0]
palabras_tristeza_orden <-sort(table(unlist(palabras_tristeza)),
decreasing = TRUE)
head(palabras_tristeza_orden,n=10)
##
## triste dolor azul gris soledad
## 4 2 1 1 1
secuencia_sentimientos <-(sentimientos_df$negative*-1)+sentimientos_df$positive
simple_plot(secuencia_sentimientos)
# install.packages("syuzhet")
# install.packages("RColorBrewer")
library(syuzhet)
library(RColorBrewer)
texto_himno <-read.delim("C:\\Users\\luisa\\Documents\\R LUISA\\MODULO 4\\himnomexicano.txt",header=FALSE)
#View(texto_himno)
## [1] "c" "mexicanos" "u2029al" "u2029grito" "u2029de"
## [6] "u2029guerra"
## [1] 285
sentimientos1_df <- get_nrc_sentiment(texto_palabras1,language="spanish")
#Idiomas disponibles: Spanish, English, French, German, Italian, Portuguese, entre otros.
summary(sentimientos1_df)
## anger anticipation disgust fear
## 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.06667 Mean :0.02456 Mean :0.01754 Mean :0.08772
## 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.00000
## Max. :2.00000 Max. :2.00000 Max. :1.00000 Max. :2.00000
## 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.03509 Mean :0.05614 Mean :0.02105 Mean :0.04211
## 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.00000
## Max. :2.00000 Max. :1.00000 Max. :2.00000 Max. :2.00000
## negative positive
## Min. :0.0000 Min. :0.00000
## 1st Qu.:0.0000 1st Qu.:0.00000
## Median :0.0000 Median :0.00000
## Mean :0.1018 Mean :0.09474
## 3rd Qu.:0.0000 3rd Qu.:0.00000
## Max. :2.0000 Max. :2.00000
## 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 0 0 0 0 0 0 0 0 0 0
## 4 2 0 0 1 0 1 2 0 2 0
## 5 0 0 0 0 0 0 0 0 0 0
## 6 1 0 0 2 0 1 0 0 2 0
barplot(
colSums(prop.table(sentimientos1_df[1:8])),
space= 0.2,
horiz= FALSE,
las =1,
cex.names = 0.7,
col= brewer.pal(n=8,name="Set3"),
main= "ANÁLISIS DE SENTIMIENTOS HIMNO NACIONAL MEXICANO",
xlab= "EMOCIONES"
)
palabras_fear <- texto_palabras1[sentimientos1_df$fear>0]
palabras_fear_orden <-sort(table(unlist(palabras_fear)),
decreasing = TRUE)
head(palabras_fear_orden,n=10)
##
## u2029guerra guerra u2029grito u2029sangre sangre u2029destino
## 5 3 2 2 1 1
## u2029dios u2029enemigo
## 1 1
secuencia_sentimientos1<-(sentimientos1_df$negative*-1)+sentimientos1_df$positive
simple_plot(secuencia_sentimientos1)