---
title: "Text Mining of Permanent Downhole Gauges"
author: "Vignette Author"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Text Mining of Permanent Downhole Gauges}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r}
library(petro.One)
library(tm)

my_url <- make_search_url(query = "Permanent Downhole Gauge", 
                          how = "all")        

get_papers_count(my_url)    # how many papers total
papers_by_type(my_url)      # papers by type

# create a dataframe of papers found
df <- read_multidoc(my_url)
df
```

```{r}
library(petro.One)

term_freq <- term_frequency(df)
term_freq
```

```{r fig.height=9, fig.width=6}
library(petro.One)

plot_wordcloud(df, max.words = 100, min.freq = 15)
```

## Bar plot

```{r}
plot_bars(df, min.freq = 25)
```


## dendogram

```{r}
plot_relationships(df, min.freq = 25, threshold = 0.1)
```

```{r}
library(cluster)   
tdm <- get_term_document_matrix(df)$tdm

tdm.rst <- removeSparseTerms(tdm, 0.93)

d <- dist(tdm.rst, method="euclidian")   
fit <- hclust(d=d, method="complete")   # for a different look try substituting: method="ward.D"
fit 
```

```{r}
plot(fit, hang = 1)
```

