系統參數設定

## [1] ""

安裝需要的packages

install library

1. 資料前處理

(1). 文章斷詞

設定斷詞引擎

(2). 資料基本清理

  • 日期格式化
  • 去除特殊字元、詞頻太低的字
## `summarise()` has grouped output by 'artDate'. You can override using the `.groups` argument.
## # A tibble: 2,103 x 3
## # Groups:   artDate [4]
##    artDate    word       count
##    <date>     <chr>      <int>
##  1 2021-03-25 長榮         432
##  2 2021-03-24 長榮         311
##  3 2021-03-25 運河         271
##  4 2021-03-25 台灣         240
##  5 2021-03-25 塞子         216
##  6 2021-03-25 蘇伊士運河   175
##  7 2021-03-25 日本         140
##  8 2021-03-24 運河         136
##  9 2021-03-25 真的         133
## 10 2021-03-25 埃及         129
## # ... with 2,093 more rows

2. 準備LIWC字典

全名Linguistic Inquiry and Word Counts,由心理學家Pennebaker於2001出版 分為正向情緒與負向情緒

讀檔,字詞間以“,”將字分隔

## [1] "character"

分割字詞,並將兩個情緒字典併在一起

##       word sentiment
## 1     一流  positive
## 2 下定決心  positive
## 3 不拘小節  positive
## 4   不費力  positive
## 5     不錯  positive
## 6     主動  positive

3. 將文章和與LIWC情緒字典做join

在畫出情緒之前,先看看每天的發文情形,大約在3月25日有最多的討論數。

正負情緒發文折線圖

找出文集中,對於LIWC字典是positive和negative的字

算出每天情緒總和(sentiment_count),可以看出23日和26日時情緒為positive較多,其餘則為negative較多。

## `summarise()` has grouped output by 'artDate'. You can override using the `.groups` argument.
## # A tibble: 8 x 3
## # Groups:   artDate [4]
##   artDate    sentiment count
##   <date>     <chr>     <int>
## 1 2021-03-23 negative     92
## 2 2021-03-23 positive     98
## 3 2021-03-24 negative    307
## 4 2021-03-24 positive    271
## 5 2021-03-25 negative    586
## 6 2021-03-25 positive    453
## 7 2021-03-26 negative     72
## 8 2021-03-26 positive     76

4. 畫出文字雲

挑出有興趣的日期,畫出文字雲看看都在討論甚麼主題。

## Joining, by = "word"
## # A tibble: 69 x 4
## # Groups:   artDate [1]
##    artDate    word  count sentiment
##    <date>     <chr> <int> <chr>    
##  1 2021-03-25 問題     57 negative 
##  2 2021-03-25 損失     52 negative 
##  3 2021-03-25 重要     33 positive 
##  4 2021-03-25 嚴重     30 negative 
##  5 2021-03-25 幫忙     29 positive 
##  6 2021-03-25 不爽     26 negative 
##  7 2021-03-25 解決     26 positive 
##  8 2021-03-25 謝謝     25 positive 
##  9 2021-03-25 喜歡     21 positive 
## 10 2021-03-25 可憐     15 negative 
## # ... with 59 more rows

2021-03-25 文字雲

## Adding missing grouping variables: `artDate`
## Joining, by = "word"
## # A tibble: 40 x 4
## # Groups:   artDate [1]
##    artDate    word  count sentiment
##    <date>     <chr> <int> <chr>    
##  1 2021-03-24 問題     42 negative 
##  2 2021-03-24 解決     20 positive 
##  3 2021-03-24 協助     16 positive 
##  4 2021-03-24 幫忙     13 positive 
##  5 2021-03-24 簡單     12 positive 
##  6 2021-03-24 重要     11 positive 
##  7 2021-03-24 謝謝     11 positive 
##  8 2021-03-24 丟臉     10 negative 
##  9 2021-03-24 損失     10 negative 
## 10 2021-03-24 可憐      9 negative 
## # ... with 30 more rows
## Joining, by = "word"
## # A tibble: 12 x 4
## # Groups:   artDate [1]
##    artDate    word  count sentiment
##    <date>     <chr> <int> <chr>    
##  1 2021-03-23 謝謝     20 positive 
##  2 2021-03-23 問題     15 negative 
##  3 2021-03-23 成功      6 positive 
##  4 2021-03-23 故障      6 negative 
##  5 2021-03-23 喜歡      6 positive 
##  6 2021-03-23 垃圾      5 negative 
##  7 2021-03-23 嚴重      5 negative 
##  8 2021-03-23 完美      4 positive 
##  9 2021-03-23 感謝      4 positive 
## 10 2021-03-23 解決      4 positive 
## 11 2021-03-23 幫忙      4 positive 
## 12 2021-03-23 簡單      4 positive

2021-03-23 文字雲

5.找出情緒字典代表字

算出所有字詞的詞頻(sentiment_sum),找出情緒代表字,負面詞包含問題、損失、嚴重;正面詞包含解決、幫忙…等。

6.歸類正負面文章

之前的情緒分析大部分是全部的詞彙加總,接下來將正負面情緒的文章分開,看看能不能發現一些新的東西。接下來歸類文章,將每一篇文章正負面情緒的分數算出來,然後大概分類文章屬於正面還是負面。 分析結果為負面文章的比例較多。

## Joining, by = "word"
## `summarise()` has grouped output by 'artUrl'. You can override using the `.groups` argument.
## # A tibble: 2 x 2
##   type     count
## * <chr>    <int>
## 1 negative   100
## 2 positive    70

情緒關鍵字:正面情緒文章

## Joining, by = "word"
## `summarise()` has grouped output by 'word'. You can override using the `.groups` argument.

結合聯合新聞網的資料,計算每天正負面情緒的數量,發現兩個平台的負面情緒都較高,尤其3月25日特別明顯。

## [1] "2021/03/24" "2021/03/26"
## Joining, by = "word"
## `summarise()` has grouped output by 'artDate', 'sentiment'. You can override using the `.groups` argument.

結論

長榮海運「長賜輪」(Ever Given)23日上午擱淺卡道蘇伊士運河,嚴重影響全球船運時程,不過這起「航運界重大意外」與「奇談」也引起全球國際媒體大幅報導,本組抓取PTT八卦版有關長榮海運此事件,23日開始被討論在25日討論最為熱烈。 從23日文字雲出現塞子、世界之光等文字,符合韓國瑜的「塞子說」及網友附和的「台灣第一次影響全世界」,長榮事件討論度越來越高,更登上國際版面,意外讓台灣出名了,以至於一開始的情緒分析為positive。 由25日的文字雲來看因為造成運河壅塞,長榮後續可能會被罰錢,而大家關心的咎責賠償問題及長賜號屬日本正榮汽船公司都是被大家廣為討論的。

從正負面情緒文章數看出負面文章比例較多,負面情緒關鍵字多為問題、損失、嚴重;正面情緒關鍵字為解決、重要、幫忙等 ,也符合上述文字雲中大家討論的觀點。

本組也比較PTT及聯合新聞網中每天文章的正負情緒變化,從圖可知25號是討論度最多及情緒轉折的一天。