forked from vanatteveldt/topicbrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
54 lines (39 loc) · 1.65 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Browse LDA Topic Models
========================================================
This package allows you to create a set of HTML files to browse a topic model.
It creates a word cloud and time-graph per topic, and annotates a selection of documents with the topic for each word.
See the [the example](http://rpubs.com/vanatteveldt/topicbrowser) for a collection of State of the Union addresses.
Installing
----
```{r message=FALSE}
if (!require(devtools)) {install.packages("devtools"); library(devtools)}
install_github("vanatteveldt/topicbrowser")
library(topicbrowser)
```
Creating a topic browser
----
To create a topic browser, you need to have:
- A model fit using `topicmodels::LDA`
- The set of original tokens used to create the document term matrix, and the document ids these tokens are from
- The metadata of the documents, containing aid, headline, and date
The provided data file 'sotu' contains this data from the state of the union addresses.
Make sure that the tokens are ordered in the way they appeared in the article
```{r}
data(sotu)
tokens = tokens[order(tokens$aid, tokens$id), ]
class(m)
head(tokens)
head(meta)
```
With these data, you can create a topic browser as follows:
```{r warning=FALSE, fig.keep='none'}
output = createTopicBrowser(m, tokens$lemma, tokens$aid, words=tokens$word, meta=meta)
```
You can also publish the output file directly using `markdown::rpubsupload`:
```{r eval=FALSE}
library(markdown)
result = rpubsUpload("Example topic browser", output)
browseURL(result$continueUrl)
```
This produces the results shown in the [the example](http://rpubs.com/vanatteveldt/topicbrowser)
<!-- library(knitr); knit("README.Rmd") -->