Twitter 热门话题

用 R 分析社交媒体数据

Vivek Vijayaraghavan

Data Science Coach

课程概览

  • 了解 Twitter 热门趋势
  • 提取热门话题
  • 用趋势提升参与与互动
用 R 分析社交媒体数据

什么是 Twitter 趋势?

  • 当前流行的关键词、事件或话题
  • 发现最热的新兴讨论
  • 部分趋势带有话题标签
  • 话题标签便于搜索相关讨论
  • 位置趋势用于识别特定地点的话题
用 R 分析社交媒体数据

利用 Twitter 趋势的力量

  • 将营销信息与热门话题结合
  • 趋势可提升推文互动
  • 旅游平台可围绕"#TravelTuesday"发推
用 R 分析社交媒体数据

提取全球趋势

# Get overall current trending topics
trend_topics <- get_trends()
head(trend_topics$trend, 10)
 [1] "#madebygoogle"         "#あなたとHしたい人の数"
 [3] "西田くん"                "Jennifer Aniston"      
 [5] "#ワールドカップバレー"     "#FelizMartes"          
 [7] "#G線上のあなたと私"       "西田选手"              
 [9] "피디수첩"                "タジキスタン"
  • 聚焦特定地区的趋势更有意义
用 R 分析社交媒体数据

有当前趋势的位置

# Extract locations of available twitter trends
trends_avail <- trends_available()
head(trends_avail)
name                        url                          parentid    country
<chr>                      <chr>                           <int>      <chr>
Worldwide     http://where.yahooapis.com/v1/place/1            
Winnipeg      http://where.yahooapis.com/v1/place/2972    23424775    Canada
Ottawa        http://where.yahooapis.com/v1/place/3369    23424775    Canada    
Quebec        http://where.yahooapis.com/v1/place/3444    23424775    Canada    
Montreal      http://where.yahooapis.com/v1/place/3534    23424775    Canada    
Toronto       http://where.yahooapis.com/v1/place/4118    23424775    Canada
用 R 分析社交媒体数据

按国家的热门话题

# Get trending topics in the US
gt_US <- get_trends("United States")
用 R 分析社交媒体数据

按国家的热门话题

View(gt_US)

美国的热门话题

  • 音乐视频公司可围绕"hashtagRockHall2020"投放推广
用 R 分析社交媒体数据

按城市的热门话题

  • 查找特定城市的趋势
  • 关联该趋势附近的推文
# Get trending topics in New York
gt_city <- get_trends("New York")
用 R 分析社交媒体数据

按城市的热门话题

head(gt_city)

trend                            url                        promoted_content
<chr>                           <chr>                             <lgl>
Lions            http://twitter.com/search?q=Lions                  NA    
Green Bay        http://twitter.com/search?q=%22Green+Bay%22        NA    
#DETvsGB         http://twitter.com/search?q=%23DETvsGB             NA    
LeBron           http://twitter.com/search?q=LeBron                 NA    
Aaron Rodgers    http://twitter.com/search?q=%22Aaron+Rodgers%22    NA    
#90DayFiance     http://twitter.com/search?q=%2390DayFiance         NA
  • 篮球周边品牌可借势该趋势
用 R 分析社交媒体数据

推文量最高的趋势

  • tweet_volume 为该话题的推文数量
  • 仅对部分趋势提供
  • 用于找出推文量最高的趋势
用 R 分析社交媒体数据

推文量最高的趋势

# Aggregate trends and tweet volumes
library(dplyr)
trend_df <- gt_city %>%
              group_by(trend) %>%
              summarize(tweet_vol = mean(tweet_volume))
用 R 分析社交媒体数据

推文量最高的趋势

head(trend_df)
trend                  tweet_vol
<chr>                    <dbl>
#90DayFiance             14375            
#acefamilyisoverparty    12760            
#ascendwithme            NA            
#bbcon2019               NA            
#bookbirthday            NA            
#DemDebate               18928
用 R 分析社交媒体数据

推文量最高的趋势

# Sort data frame on descending order of tweet volumes
trend_df_sort <- arrange(trend_df, desc(tweet_vol))
用 R 分析社交媒体数据

推文量最高的趋势

# View the most tweeted trends
head(trend_df_sort)
trend              tweet_vol
<chr>               <dbl>
LeBron              298302            
Lions               267945            
Columbus Day        135014            
John Bolton         118933            
#DETvsGB            67197            
#TuesdayThoughts    63259
  • 旅游公司可围绕"Columbus Day"推广度假套餐
用 R 分析社交媒体数据

Passons à la pratique !

用 R 分析社交媒体数据

Preparing Video For Download...