<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/ldavis-show-case-on-r-bloggers/"></div></div><div><a data-url="http://www.r-bloggers.com/ldavis-show-case-on-r-bloggers/" data-counturl="http://www.r-bloggers.com/ldavis-show-case-on-r-bloggers/" data-count="horizontal" data-text="LDAvis Show Case on R-Bloggers" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-addict.com/2016/06/21/LDAvis-RBloggers.html"> http://r-addict.com</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img src="http://i0.wp.com/r-addict.com/images/fulls/LDAvis.png?w=456" data-recalc-dims="1">Text mining is a new challenge for machine wandering practitioners. The increased interest in the text mining is caused by an augmentation of internet users and by rapid growth of the internet data which is said that <em>in 80% is a text data</em>. Extracting information from articles, news, posts and comments have became a desirable skill but what is even more needful are tools for text mining models diagnostics and visualizations. Such visualizations enable to better understand the insight from a model and provides an easy interface for presenting your research results to greater audience. In this post I present the Latent Dirichlet Allocation text mining model for text classification into topics and a great <a target="_blank" href="https://cran.r-project.org/web/packages/LDAvis/index.html">LDAvis</a> package for interactive visualizations of topic models. All this on <a target="_blank" href="http://r-bloggers.com/">R-Bloggers</a> posts!</p>
<p>LDAvis is not my package. It is created by <a target="_blank" href="https://github.com/cpsievert">cpsievert</a> and this post’s code for LDAvis-preparations is mostly based on his LDAvis tutorial: <a target="_blank" href="http://cpsievert.github.io/LDAvis/reviews/reviews.html">A topic model for movie reviews</a></p>
<h1>LDA overview and text preparation</h1>
<p>From <a target="_blank" href="https://en.wikipedia.org/wiki/Latent_Dirichlet_allocation">Wikipedia</a></p>
<blockquote>
<p>In natural language processing, latent Dirichlet allocation (LDA) is a generative statistical model that allows sets of observations to be explained by unobserved groups that explain why some parts of the data are similar. For example, if observations are words collected into documents, it posits that each document is a mixture of a small number of topics and that each word’s creation is attributable to one of the document’s topics.</p>
</blockquote>
<p>For this post I have used articles from <a target="_blank" href="http://r-bloggers.com/">R-Bloggers</a>.<br>
They can be downloaded from <a target="_blank" href="https://github.com/MarcinKosinski/r-bloggers-harvesting">this repository</a>. The data harvesting process is explained at the end of this post.</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>RSQLite</span><span>)</span>
<span>db.conn</span> <span>&lt;-</span> 
  <span>dbConnect</span><span>(</span>
    <span>dbDriver</span><span>(</span><span>&quot;SQLite&quot;</span><span>),</span>
    <span>&quot;r-bloggers.db&quot;</span>
<span>)</span>
<span>posts</span> <span>&lt;-</span> <span>dbGetQuery</span><span>(</span><span>db.conn</span><span>,</span> 
           <span>&quot;SELECT text from posts&quot;</span><span>)</span>
<span>dbDisconnect</span><span>(</span><span>db.conn</span><span>)</span></code></pre>
</figure>
<p>Normally I would use <code>LDA()</code> function from <a target="_blank" href="https://cran.r-project.org/web/packages/topicmodels/topicmodels.pdf">topicmodels</a> package to fit LDA model because the input can be of class <code>DocumentTermMatrix</code> which is an object from <a target="_blank" href="https://cran.r-project.org/web/packages/tm/vignettes/tm.pdf">tm</a> package. <code>DocumentTermMatrix</code> object is very convinient for working with text data (<a target="_blank" href="http://www.rexamine.com/2014/06/text-mining-in-r-automatic-categorization-of-wikipedia-articles/">check this Norbert Ryciak’s post</a>) because there exists <code>tm_map</code> function which can be applied to all documents for stop words removal, lowering capital letters and removal of words that did not occur in x % of documents. I haven’t seen <code>LDAvis</code> examples for models generated with topicsmodel package so we will use traditional approach to text processing. The <a target="_blank" href="https://en.wikipedia.org/wiki/Lemmatisation">stemming</a> and stopwords removal was perfored during the data collection, which is described at the end of the post.</p>
<figure>
<pre><code data-lang="r"><span>## the following fragment of code in this section
## is motivated by
## http://cpsievert.github.io/LDAvis/reviews/reviews.html
# tokenize on space and output as a list:
</span><span>doc.list</span> <span>&lt;-</span> <span>strsplit</span><span>(</span><span>posts</span><span>[,</span> <span>1</span><span>],</span> <span>&quot;[[:space:]]+&quot;</span><span>)</span>
<span># compute the table of terms:
</span><span>term.table</span> <span>&lt;-</span> <span>table</span><span>(</span><span>unlist</span><span>(</span><span>doc.list</span><span>))</span>
<span>term.table</span> <span>&lt;-</span> <span>sort</span><span>(</span><span>term.table</span><span>,</span> <span>decreasing</span> <span>=</span> <span>TRUE</span><span>)</span>
<span># remove terms that occur fewer than 5 times:
</span><span>term.table</span> <span>&lt;-</span> <span>term.table</span><span>[</span><span>term.table</span> <span>></span> <span>5</span><span>]</span>
<span>vocab</span> <span>&lt;-</span> <span>names</span><span>(</span><span>term.table</span><span>)</span></code></pre>
</figure>
<p>The <code>lda.collapsed.gibbs.sampler()</code> function from <code>tm</code> package has uncomfortable input format (regarding to <code>LDA()</code> from topicmodels package) so I basically used <a target="_blank" href="https://github.com/cpsievert">cpsievert</a> snippets</p>
<figure>
<pre><code data-lang="r"><span># now put the documents into the format required by the lda package:
</span><span>get.terms</span> <span>&lt;-</span> <span>function</span><span>(</span><span>x</span><span>)</span> <span>{</span>
  <span>index</span> <span>&lt;-</span> <span>match</span><span>(</span><span>x</span><span>,</span> <span>vocab</span><span>)</span>
  <span>index</span> <span>&lt;-</span> <span>index</span><span>[</span><span>!</span><span>is.na</span><span>(</span><span>index</span><span>)]</span>
  <span>rbind</span><span>(</span><span>as.integer</span><span>(</span><span>index</span> <span>-</span> <span>1</span><span>),</span> <span>as.integer</span><span>(</span><span>rep</span><span>(</span><span>1</span><span>,</span> <span>length</span><span>(</span><span>index</span><span>))))</span>
<span>}</span>
<span>documents</span> <span>&lt;-</span> <span>lapply</span><span>(</span><span>doc.list</span><span>,</span> <span>get.terms</span><span>)</span>

<span># Compute some statistics related to the data set:
</span><span>D</span> <span>&lt;-</span> <span>length</span><span>(</span><span>documents</span><span>)</span>  <span># number of documents (3740)
</span><span>W</span> <span>&lt;-</span> <span>length</span><span>(</span><span>vocab</span><span>)</span>  <span># number of terms in the vocab (18,536)
</span><span>doc.length</span> <span>&lt;-</span> <span>sapply</span><span>(</span><span>documents</span><span>,</span> 
                     <span>function</span><span>(</span><span>x</span><span>)</span> <span>sum</span><span>(</span><span>x</span><span>[</span><span>2</span><span>,</span> <span>]))</span>  
<span># number of tokens per document [312, 288, 170, 436, 291, ...]
</span><span>N</span> <span>&lt;-</span> <span>sum</span><span>(</span><span>doc.length</span><span>)</span>  <span># total number of tokens in the data (546,827)
</span><span>term.frequency</span> <span>&lt;-</span> <span>as.integer</span><span>(</span><span>term.table</span><span>)</span>  
<span>#</span> <span>frequencies</span> <span>of</span> <span>terms</span> <span>in</span> <span>the</span> <span>corpus</span> <span>[</span><span>8939</span><span>,</span> <span>5544</span><span>,</span> <span>2411</span><span>,</span> <span>2410</span><span>,</span> <span>2143</span><span>,</span> <span>...</span><span>]</span></code></pre>
</figure>
<p>Fitting the model: from <code>tm</code> package documentation</p>
<blockquote>
<p>… [this function] takes sparsely represented input documents, perform inference, and return point estimates of the latent parameters using the state at the last iteration of Gibbs sampling.</p>
</blockquote>
<figure>
<pre><code data-lang="r"><span># MCMC and model tuning parameters:
</span><span>K</span> <span>&lt;-</span> <span>20</span>
<span>G</span> <span>&lt;-</span> <span>5000</span>
<span>alpha</span> <span>&lt;-</span> <span>0.02</span>
<span>eta</span> <span>&lt;-</span> <span>0.02</span>

<span># Fit the model:
</span><span>library</span><span>(</span><span>lda</span><span>)</span>
<span>set.seed</span><span>(</span><span>456</span><span>)</span>
<span>t1</span> <span>&lt;-</span> <span>Sys.time</span><span>()</span>
<span>fit</span> <span>&lt;-</span> <span>lda.collapsed.gibbs.sampler</span><span>(</span>
  <span>documents</span> <span>=</span> <span>documents</span><span>,</span> <span>K</span> <span>=</span> <span>K</span><span>,</span> 
  <span>vocab</span> <span>=</span> <span>vocab</span><span>,</span> <span>num.iterations</span> <span>=</span> <span>G</span><span>,</span> 
  <span>alpha</span> <span>=</span> <span>alpha</span><span>,</span> <span>eta</span> <span>=</span> <span>eta</span><span>,</span> 
  <span>initial</span> <span>=</span> <span>NULL</span><span>,</span> <span>burnin</span> <span>=</span> <span>0</span><span>,</span>
  <span>compute.log.likelihood</span> <span>=</span> <span>TRUE</span>
<span>)</span>
<span>t2</span> <span>&lt;-</span> <span>Sys.time</span><span>()</span>
<span>t2</span> <span>-</span> <span>t1</span>  <span># about 7 seconds on my laptop
</span>
<span>library</span><span>(</span><span>archivist</span><span>)</span>
<span>saveToRepo</span><span>(</span><span>fit</span><span>,</span>
           <span>repoDir</span> <span>=</span> <span>&quot;../Museum&quot;</span><span>)</span></code></pre>
</figure>
<p>The computations took very long, so in case you would like to<br>
get model faster, I have archived my model on GitHub with the help of<br>
<a target="_blank" href="http://r-bloggers.com/r-hero-saves-backup-city-with-archivist-and-github/">archivist</a> package.<br>
You can easily load this model to R with</p>
<figure>
<pre><code data-lang="r"><span>archivist</span><span>::</span><span>aread</span><span>(</span><span>'MarcinKosinski/Museum/fa93abf0ff93a7f6f3f0c42b7935ad4d'</span><span>)</span> <span>-></span> <span>fit</span></code></pre>
</figure>
<h1>LDAvis use case</h1>
<p>If you google out properly you’ll wind out that LDAvis description is</p>
<blockquote>
<p>Tools to create an interactive web-based visualization of a topic model that has been fit to a corpus of text data using Latent Dirichlet Allocation (LDA). Given the estimated parameters of the topic model, it computes various summary statistics as input to an interactive visualization built with D3.js that is accessed via a browser. The goal is to help users interpret the topics in their LDA topic model.</p>
</blockquote>
<p><a target="_blank" href="https://cran.r-project.org/web/packages/LDAvis/vignettes/details.pdf">Detailed vignette about LDAvis input and output can be found here</a>.</p>
<blockquote>
<p>To visualize the result using LDAvis, we’ll need estimates of the document-topic distributions, which we denote by the DxK matrix theta, and the set of topic-term distributions, which we denote by the K×W matrix phi.</p>
</blockquote>
<figure>
<pre><code data-lang="r"><span>theta</span> <span>&lt;-</span> <span>t</span><span>(</span><span>apply</span><span>(</span><span>fit</span><span>$</span><span>document_sums</span> <span>+</span> <span>alpha</span><span>,</span>
                 <span>2</span><span>,</span>
                 <span>function</span><span>(</span><span>x</span><span>)</span> <span>x</span><span>/</span><span>sum</span><span>(</span><span>x</span><span>)))</span>
<span>phi</span> <span>&lt;-</span> <span>t</span><span>(</span><span>apply</span><span>(</span><span>t</span><span>(</span><span>fit</span><span>$</span><span>topics</span><span>)</span> <span>+</span> <span>eta</span><span>,</span>
               <span>2</span><span>,</span>
               <span>function</span><span>(</span><span>x</span><span>)</span> <span>x</span><span>/</span><span>sum</span><span>(</span><span>x</span><span>)))</span></code></pre>
</figure>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>LDAvis</span><span>)</span>
<span># create the JSON object to feed the visualization:
</span><span>json</span> <span>&lt;-</span> <span>createJSON</span><span>(</span>
  <span>phi</span> <span>=</span> <span>phi</span><span>,</span> 
  <span>theta</span> <span>=</span> <span>theta</span><span>,</span> 
  <span>doc.length</span> <span>=</span> <span>doc.length</span><span>,</span> 
  <span>vocab</span> <span>=</span> <span>vocab</span><span>,</span> 
  <span>term.frequency</span> <span>=</span> <span>term.frequency</span>
<span>)</span>
<span>serVis</span><span>(</span><span>json</span><span>,</span> <span>out.dir</span> <span>=</span> <span>'vis'</span><span>,</span> 
       <span>open.browser</span> <span>=</span> <span>FALSE</span><span>)</span></code></pre>
</figure>
<p>The result is published under this link <a target="_blank" href="http://r-addict.com/r-bloggers-harvesting/">http://r-addict.com/r-bloggers-harvesting/</a> where you can check Intertopic Distance Map (via multidimensional scaling) and top N relevant terms for a topic.</p>
<h1>Data Harvesting</h1>
<p>Below is the code I have used for R-Bloggers web-scraping. At start I have extracted all links to posts<br>
from first 100 main pages of R-Bloggers. Then I have created an SQLite database with empty table called <code>posts</code>.<br>
This table has been used to store information like: post title, post link, post author, date of publication and the whole post text. For the text I have extracted only words (with <a target="_blank" href="http://www.gagolewski.com/software/stringi/">stringi</a> package) that have length greater than 1 and applied <code>tolower</code> function to get rid of capital letters. Stop words removal was done thanks to <code>tm::removeWords()</code>. For <a target="_blank" href="https://en.wikipedia.org/wiki/Stemming">stemming</a> I have used <a target="_blank" href="https://cran.r-project.org/web/packages/RWeka/RWeka.pdf">RWeka::LovinsStemmer</a>. I did not perform full lemmatization as I have found it troubling in R (couldn’t install <a target="_blank" href="http://stackoverflow.com/questions/28214148/how-to-perform-lemmatization-in-r">this</a> and <a target="_blank" href="http://stackoverflow.com/questions/22993796/lemmatizer-in-r-or-python-am-are-is-be">this</a> took too long).</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>rvest</span><span>)</span>
<span>library</span><span>(</span><span>pbapply</span><span>)</span>
<span>pbsapply</span><span>(</span><span>1</span><span>:</span><span>100</span><span>,</span> <span>function</span><span>(</span><span>i</span><span>){</span>
  <span>read_html</span><span>(</span><span>paste0</span><span>(</span><span>'http://www.r-bloggers.com/page/'</span><span>,</span> <span>i</span><span>))</span> <span>%>%</span>
  <span>html_nodes</span><span>(</span><span>'h2 a'</span><span>)</span> <span>%>%</span>
  <span>html_attr</span><span>(</span><span>'href'</span><span>)</span> <span>%>%</span>
  <span>grep</span><span>(</span><span>'r-bloggers'</span><span>,</span> <span>x</span> <span>=</span> <span>.</span><span>,</span> <span>value</span> <span>=</span> <span>TRUE</span><span>)</span>
<span>})</span> <span>%>%</span> 
  <span>as.vector</span><span>()</span> <span>%>%</span>
  <span>unique</span> <span>-></span> <span>links</span>


<span># create connection
</span><span>library</span><span>(</span><span>RSQLite</span><span>)</span>
<span>db.conn</span> <span>&lt;-</span> 
  <span>dbConnect</span><span>(</span>
    <span>dbDriver</span><span>(</span><span>&quot;SQLite&quot;</span><span>),</span>
    <span>&quot;r-bloggers.db&quot;</span>
<span>)</span>
<span># create empty table for posts
</span><span>posts</span> <span>&lt;-</span> 
  <span>data.frame</span><span>(</span><span>link</span> <span>=</span> <span>&quot;&quot;</span><span>,</span>
             <span>title</span> <span>=</span> <span>&quot;&quot;</span><span>,</span>
             <span># shares = &quot;&quot;,
</span>             <span>text</span> <span>=</span> <span>&quot;&quot;</span><span>,</span>
             <span>date</span> <span>=</span> <span>&quot;&quot;</span><span>,</span>
             <span>author</span> <span>=</span> <span>&quot;&quot;</span><span>)</span>
<span>dbWriteTable</span><span>(</span>
  <span>db.conn</span><span>,</span>
  <span>name</span> <span>=</span> <span>&quot;posts&quot;</span><span>,</span>
  <span>posts</span><span>,</span>
  <span>overwrite</span> <span>=</span> <span>TRUE</span><span>,</span>
  <span>row.names</span> <span>=</span> <span>FALSE</span>
<span>)</span> 

<span># function for info extraction
</span><span>library</span><span>(</span><span>stringi</span><span>)</span>
<span>library</span><span>(</span><span>tm</span><span>)</span>
<span>library</span><span>(</span><span>RWeka</span><span>)</span>
<span>postInfo</span> <span>&lt;-</span> <span>function</span><span>(</span><span>link</span><span>,</span> <span>conn</span><span>)</span> <span>{</span>
  <span>post</span> <span>&lt;-</span> <span>read_html</span><span>(</span><span>link</span><span>)</span>
  <span>title</span> <span>&lt;-</span> <span>html_nodes</span><span>(</span><span>post</span><span>,</span> <span>'h1'</span><span>)</span> <span>%>%</span>
    <span>html_text</span><span>()</span> <span>%>%</span>
    <span>.</span><span>[</span><span>1</span><span>]</span> <span>%>%</span>
    <span>gsub</span><span>(</span><span>&quot;\&quot;&quot;</span><span>,</span> <span>&quot;&quot;</span><span>,</span> <span>x</span> <span>=</span> <span>.</span><span>)</span> 
  <span># shares &lt;- html_nodes(post,
</span>  <span># '.wpusb-counts , .wpusb-counts span') %>%
</span>  <span># html_text()
</span>  <span>text</span> <span>&lt;-</span> <span>html_nodes</span><span>(</span><span>post</span><span>,</span> <span>'p'</span><span>)</span> <span>%>%</span> 
    <span>html_text</span><span>()</span> <span>%>%</span> <span>head</span><span>(</span><span>-1</span><span>)</span> <span>%>%</span>
    <span>paste</span><span>(</span><span>collapse</span><span>=</span><span>&quot; &quot;</span><span>)</span> <span>%>%</span>
    <span>gsub</span><span>(</span><span>&quot;\&quot;&quot;</span><span>,</span> <span>&quot;&quot;</span><span>,</span> <span>x</span> <span>=</span> <span>.</span><span>)</span> <span>%>%</span>
    <span>stri_extract_all_words</span><span>()</span>  <span>%>%</span> 
    <span>.</span><span>[[</span><span>1</span><span>]]</span> 
  <span>text</span> <span>&lt;-</span> <span>text</span><span>[</span><span>stri_length</span><span>(</span><span>text</span><span>)</span> <span>></span> <span>1</span><span>]</span> <span>%>%</span>
    <span>tolower</span><span>()</span> <span>%>%</span>
    <span>gsub</span><span>(</span><span>&quot;\\.&quot;</span><span>,</span> <span>&quot; &quot;</span><span>,</span> <span>x</span> <span>=</span> <span>.</span><span>)</span> <span>%>%</span>
    <span>removeWords</span><span>(</span><span>c</span><span>(</span><span>stopwords</span><span>(</span><span>'english'</span><span>),</span>
                  <span>stopwords</span><span>(</span><span>'SMART'</span><span>),</span>
                  <span>&quot;&quot;</span><span>,</span> <span>&quot;’s&quot;</span><span>,</span> <span>&quot;amp&quot;</span><span>,</span> 
                  <span>&quot;div&quot;</span><span>,</span> <span>&quot;’ve&quot;</span><span>,</span> <span>1</span><span>:</span><span>100</span><span>,</span> 
                  <span>&quot;’ll&quot;</span><span>,</span> <span>&quot;let’s&quot;</span><span>,</span> <span>&quot;’re&quot;</span><span>,</span> 
                  <span>&quot;’m&quot;</span><span>))</span> 
  <span>text</span> <span>&lt;-</span> <span>text</span><span>[</span><span>stri_length</span><span>(</span><span>text</span><span>)</span> <span>></span> <span>1</span><span>]</span> <span>%>%</span>
    <span>stri_extract_all_words</span><span>()</span> <span>%>%</span> 
    <span>unlist</span> <span>%>%</span>
    <span>LovinsStemmer</span><span>(</span><span>control</span> <span>=</span> <span>NULL</span><span>)</span> <span>%>%</span>
    <span>paste</span><span>(</span><span>collapse</span> <span>=</span> <span>&quot; &quot;</span><span>)</span>
  
  <span>date</span> <span>&lt;-</span> <span>html_nodes</span><span>(</span><span>post</span><span>,</span> <span>'.date'</span><span>)</span> <span>%>%</span>
    <span>html_text</span><span>()</span> <span>%>%</span>
    <span>as.Date</span><span>(</span><span>format</span><span>=</span><span>&quot;%b %d, %Y&quot;</span><span>)</span>
  <span>if</span> <span>(</span><span>is.na</span><span>(</span><span>date</span><span>))</span> <span>{</span>
    <span>date</span> <span>&lt;-</span> <span>&quot;&quot;</span>
  <span>}</span>
  <span>author</span> <span>&lt;-</span> <span>html_nodes</span><span>(</span><span>post</span><span>,</span> <span>'.meta'</span><span>)</span> <span>%>%</span> 
    <span>html_text</span><span>()</span> <span>%>%</span> <span>strsplit</span><span>(</span><span>&quot;By &quot;</span><span>)</span> <span>%>%</span> 
    <span># second element of length-1 list
</span>    <span>.</span><span>[[</span><span>1</span><span>]]</span> <span>%>%</span> <span>.</span><span>[</span><span>2</span><span>]</span> <span>%>%</span>
    <span>gsub</span><span>(</span><span>&quot;\&quot;&quot;</span><span>,</span> <span>&quot;&quot;</span><span>,</span> <span>x</span> <span>=</span> <span>.</span><span>)</span>
 
  <span>dbGetQuery</span><span>(</span>
<span>conn</span><span>,</span>
<span>paste0</span><span>(</span><span>&quot;INSERT INTO posts
(link,title, text, date, author) VALUES&quot;</span><span>,</span>
<span>&quot;(\&quot;&quot;</span><span>,</span> <span>link</span><span>,</span> <span>&quot;\&quot;,\&quot;&quot;</span><span>,</span> <span>title</span><span>,</span> <span>&quot;\&quot;,\&quot;&quot;</span><span>,</span> <span>#shares, &quot;\&quot;,\&quot;&quot;,
</span><span>text</span><span>,</span> <span>&quot;\&quot;,\&quot;&quot;</span><span>,</span> <span>date</span><span>,</span> <span>&quot;\&quot;,\&quot;&quot;</span><span>,</span> <span>author</span><span>,</span> <span>&quot;\&quot;)&quot;</span><span>)</span>
  <span>)</span>   
<span>}</span>

<span># for proper date extraction
</span><span>lct</span> <span>&lt;-</span> <span>Sys.getlocale</span><span>(</span><span>&quot;LC_TIME&quot;</span><span>)</span>
<span>Sys.setlocale</span><span>(</span><span>&quot;LC_TIME&quot;</span><span>,</span> <span>&quot;C&quot;</span><span>)</span>
<span># get info for all links
</span><span>pbsapply</span><span>(</span>
  <span>links</span><span>,</span>
  <span>postInfo</span><span>,</span> 
  <span>db.conn</span>
<span>)</span>
<span>Sys.setlocale</span><span>(</span><span>&quot;LC_TIME&quot;</span><span>,</span> <span>lct</span><span>)</span>
<span># disconnect with database
</span><span>dbDisconnect</span><span>(</span><span>db.conn</span><span>)</span></code></pre>
</figure>
<p>If you have any questions or comments, please feel free to share your ideas on the Disqus panel below.<br>
Also, if you know how to web-scrap the number of shares per R-Bloggers article then I would love to hear your feedback as I am wondering what’s the correlation between <code>Hadley Wickham</code> appearance in the post and its number of shares.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/ldavis-show-case-on-r-bloggers/"></div></div><div><a data-url="http://www.r-bloggers.com/ldavis-show-case-on-r-bloggers/" data-counturl="http://www.r-bloggers.com/ldavis-show-case-on-r-bloggers/" data-count="vertical" data-text="LDAvis Show Case on R-Bloggers" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-addict.com/2016/06/21/LDAvis-RBloggers.html"> http://r-addict.com</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/xkcqZ6cVWRo"></a></div>