我目前正在研究比較英國國會議員在議會中的角色和他們在Twitter上的角色。我從一位議員收集了Twitter數據(最重要的是原始文本)和議會發言,並希望做一個散點圖,顯示Twitter和議會(右上角)哪些詞是常見的,哪些詞不是(左下角手角落)。所以,x軸是議會中的詞頻,y軸是twitter上的詞頻。R中的詞頻散點圖(詞作爲標籤)
到目前爲止,我已經用R完成了本文的所有工作。我對R有零經驗,直到現在我只與STATA合作過。
我試着調整這個代碼(http://is-r.tumblr.com/post/37975717466/text-analysis-made-too-easy-with-the-tm-package),但我不能解決它。主要問題是編寫此代碼的人使用一個文本文檔和正則表達式來劃分哪些文本屬於哪個軸。然而,我有兩個單獨的文檔(我將它們保存爲.txt,corpi或term-document-matrices),它們應該對應於單獨的軸。
對不起,像我這樣的新手正在爲此煩惱,今年我會投入更多的時間來學習R的基礎知識,以便我可以自己解決這個問題。但是,這篇論文將於下週一發布,我現在不能做太多的回溯來解決問題。
我會很感激,如果你能幫助我,
非常感謝,
聶
編輯:我會在我所做的代碼,即使它是不太正確的方向,但這樣我可以提供我正在處理的一個適當的例子。
我已經嘗試通過在csv文件中使用文本問題來實現is.R()s方法,用虛擬變量來分類它是否是twitter文本或語音文本。我遵循這個方法,最後我甚至得到一個散點圖,但是,它繪製了數字(我認爲它是數據集中單詞所在的數字??)而不是單詞。我認爲問題可能是R將csv文件中的每一行都作爲單獨的文本文檔處理。
# in excel i built a csv dataset that contains all the text, each instance (single tweet/speech) in one line, with an added dummy variable that clarifies whether the text is a tweet or a speech ("istweet", 1=twitter).
comparison_watson.df <- read.csv(file="data/watson_combo.csv", stringsAsFactors = FALSE)
# now to make a text corpus out of the data frame
comparison_watson_corpus <- Corpus(DataframeSource(comparison_watson.df))
inspect(comparison_watson_corpus)
# now to make a term-document-matrix
comparison_watson_tdm <-TermDocumentMatrix(comparison_watson_corpus)
inspect(comparison_watson_tdm)
comparison_watson_tdm <- inspect(comparison_watson_tdm)
sort(colSums(comparison_watson_tdm))
table(colSums(comparison_watson_tdm))
termCountFrame_watson <- data.frame(Term = rownames(comparison_watson_tdm))
termCountFrame_watson$twitter <- colSums(comparison_watson_tdm[comparison_watson.df$istwitter == 1, ])
termCountFrame_watson$speech <- colSums(comparison_watson_tdm[comparison_watson.df$istwitter == 0, ])
head(termCountFrame_watson)
zp1 <- ggplot(termCountFrame_watson)
zp1 <- zp1 + geom_text(aes(x = twitter, y = speech, label = Term))
print(zp1)
那麼如何生成頻率數據或者如何繪製頻率數據呢? –
這個問題將是如何繪製它。 – nikloynes
情節(x,y)有什麼問題。你的問題到底是什麼? – ECII