我是新手,如果我的問題微不足道,請道歉。我正在嘗試對我下載但遇到問題的一些推特資料進行情緒分析。我正在嘗試遵循此示例:

它創建了一個顯示正面/負面情緒計數的條形圖。示例代碼在這里**
original_books %>%
unnest_tokens(output = word,input = text) %>%
inner_join(get_sentiments("bing")) %>%
count(book, index, sentiment) %>%
pivot_wider(names_from = sentiment,
values_from = n) %>%
mutate(sent_score = positive - negative) %>%
ggplot()
geom_col(aes(x = index, y = sent_score,
fill = book),
show.legend = F)
facet_wrap(~book,scales = "free_x")
這是我到目前為止用于我自己分析的代碼:
#twitter scraping
ref <- search_tweets(
"#refugee", n = 18000, include_rts = FALSE,lang = "en"
)
data(stop_words)
new_stops <- tibble(word = c("https", "t.co", "1", "refugee", "#refugee", "amp", "refugees",
"day", "2022", "dont", "0", "2", "@refugees", "4", "2021") ,lexicon = "sabs")
full_stop <- stop_words %>%
bind_rows(new_stops) #bind_rows adds more rows (way to merge data)
現在我想制作一個類似于上面的條形圖,但我得到一個錯誤,因為我沒有一個名為“索引”的列。我試著做一個,但沒有用。這是我嘗試使用的代碼:
ref %>%
unnest_tokens(word,text,token = "tweets") %>%
anti_join(full_stop) %>%
inner_join(get_sentiments("bing")) %>%
count(word, index, sentiment) %>%
pivot_wider(names_from = sentiment,
values_from = n) %>%
mutate(sent_score = positive - negative) %>%
ggplot() #plot the overall sentiment (pos - neg) versus index,
geom_col(aes(x = index, y = sent_score), show.legend = F)
這是錯誤的影像

任何建議都非常感謝!謝謝
ref 的內容 在
此處輸入影像描述 在
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/478379.html
下一篇:R中帶有中斷的多行x軸標簽
