knitr2wordpress and gradient_cloud Revisited
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This post serves three function:
- It allows me to revisit an old blogpost
- It let's me test out the new-ish knitr function knti2wp and RWordPress
- It enables me to avoid the massive ammount of reading I need to do and still feel like I'm doing “work”
The follwoing packages are needed to run the code:
install.packages(c("knitr", "qdap")) install.packages("RWordPress", repos = "http://www.omegahat.org/R", type = "source") library(qdap) library(knitr) library(RWordPress)
*Mac users see this link and this link
In this blogpost I explored the use of gradient word clouds. It took 31 lines of code to plot the figure. I'm lazy (though I tell other's efficient) and 31 lines is enough to keep me from exploring with the gradient word cloud. In a recent update to qdap I included a function to greatly reduce the lines of code in that post to 6, making gadient clouds more accessible.
Grab the Presidential Debate Transcript
# download transcript of the debate to working directory url_dl(pres.deb1.docx)
Read in the Data
# load multiple files with read transcript and assign to working directory dat1 <- read.transcript("pres.deb1.docx", c("person", "dialogue")) # qprep for quick cleaning dat1$dialogue <- qprep(dat1$dialogue) # view a truncated version of the data (see also htruncdf) left.just(htruncdf(dat1, 10, 45)) ## person dialogue ## 1 LEHRER We'll talk about specifically about health ca ## 2 ROMNEY What I support is no change for current retir ## 3 LEHRER And what about the vouchers? ## 4 ROMNEY So that's that's number one. Number two is fo ## 5 OBAMA Jim, if I if I can just respond very quickly, ## 6 LEHRER Talk about that in a minute. ## 7 OBAMA but but but overall. ## 8 LEHRER OK. ## 9 OBAMA And so... ## 10 ROMNEY That's that's a big topic. Can we can we stay
Remove Lehrer (need bivariate variable) and plot
dat2 <- rm_row(dat1, 1, "LEHRER") #make a bivariate column (remove LEHRER) gradient_cloud(dat2$dialogue, dat2$person, title = "Debate", X = "blue", Y = "red", stopwords = BuckleySaltonSWL, max.word.size = 2.2, min.word.size = 0.55)
Notice we have control over min/max word size, the two colors and stopwords? Easy huh?
Try a Few more with Different Parameters
gradient_cloud(dat2$dialogue, dat2$person, title = "fun", X = "green", Y = "orange") gradient_cloud(dat2$dialogue, dat2$person, title = "fun", rev.binary = TRUE) gradient_cloud(dat2$dialogue, dat2$person, title = "fun", max.word.size = 5, min.word.size = 0.025)
Now Discussion on knitr to WordPress
Here is the Rmd (text) of the file used to make this post.
Here's the format I used to send the file to WordPress.com
options(WordPressLogin = c(USERNAME = "PASSWORD"), WordPressURL = "http://trinkerrstuff.wordpress.com/xmlrpc.php") library(knitr) knit2wp(file.path("C:/Users/trinker/Desktop/gradient_clouds_revisited/PRESENTATION", "gradient_clouds_revisited.Rmd"), title = "knitr2wordpress and gradient_cloud Revisited", shortcode = TRUE) knit2wp("yourfile.Rmd", title = "knitr2wordpress and gradient_cloud Revisited")
Where USERNAME and PASSWORD are your WordPress username and password.
Please note that there was some confusion I had about where the base.url
and
base.dir
went. For more on this problem see this thread.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.