Last active
December 18, 2015 15:17
-
-
Save abresler/edf23d98b4fd08c28065 to your computer and use it in GitHub Desktop.
Netsdaily Polarity Plot in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Parsing Netsdaily for a Polarity Plot -- working with JSON | |
packages <- | |
c('magrittr', 'dplyr', 'qdap', 'jsonlite', 'ggplot2') | |
lapply(packages, library, character.only = T) | |
url <- | |
'http://www.netsdaily.com/comments/load_comments/8261850' | |
data <- | |
url %>% | |
fromJSON(simplifyDataFrame = T,flatten = T) %>% | |
.[2] %>% | |
data.frame %>% | |
tbl_df | |
names(data) %<>% gsub('comments.','',.) | |
data %<>% | |
mutate(title = title %>% tolower, | |
username = username %>% tolower) %>% | |
select(title, username) %>% | |
distinct | |
data %<>% qdap_df(text.var = 'title') | |
data %&% | |
polarity(username) %>% | |
scores %>% | |
plot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing. Nice uses of magrittr I hadn't considered many of the
%<>%
uses before. You might want to include this line as the header as it's cleaner IMO for those that may not have these packages installed already.Also I saw I had a misspelling in the warning message
qdap_df
throws. Fixed that.