การแสดงภาพ Sentiment จาก NRC
การแสดงภาพข้อมูลช่วยให้เราเห็นรูปแบบในข้อมูลได้ชัดเจนกว่าการนับตัวเลขเพียงอย่างเดียว มาลองแสดงภาพ sentiment จากพจนานุกรม nrc กัน โดยได้โหลดแพ็กเกจ tidyverse และ tidytext ไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์ข้อความเบื้องต้นใน R
คำแนะนำการฝึกหัด
- ดึงพจนานุกรม
nrcนับจำนวน sentiment และเรียงลำดับตามจำนวน เพื่อสร้างคอลัมน์ factor ใหม่ชื่อsentiment2 - แสดงภาพ
sentiment_countsโดยใช้คอลัมน์ sentiment factor ใหม่ - เปลี่ยนชื่อกราฟเป็น "Sentiment Counts in NRC" แกน x เป็น "Sentiment" และแกน y เป็น "Counts"
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Pull in the nrc dictionary, count the sentiments and reorder them by count
sentiment_counts <- ___(___) %>%
___(___) %>%
___(sentiment2 = ___(___, ___))
# Visualize sentiment_counts using the new sentiment factor column
___(___, aes(___, ___)) +
geom_col() +
coord_flip() +
# Change the title to "Sentiment Counts in NRC", x-axis to "Sentiment", and y-axis to "Counts"
___(
___ = ___,
___ = ___,
___ = ___
)