---
title: "IMtool2"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(ggplot2)
library(plotly)
library(plyr)
library(flexdashboard)
```
Search
=======================================================================
Row
-----------------------------------------------------------------------
### stat_density Example
```{r}
```
### Add Conditional Density Curves to Plot
```{r}
```
Row
-----------------------------------------------------------------------
### geom_density and facet_wrap Together
```{r}
```
### Density and Scatterplot Overlay Using geom_density
```{r}
```
Patents
=======================================================================
```{r}
library(patentsview)
library(dplyr)
library(highcharter)
library(DT)
library(knitr)
query <- with_qfuns(
or(
text_phrase(patent_abstract = "Healthcare"),
text_phrase(patent_title = "Healthcare")
)
)
fields <- c("patent_number", "assignee_organization",
"patent_num_cited_by_us_patents", "app_date", "patent_date",
"assignee_total_num_patents")
# Send an HTTP request to the PatentsView API to get data:
pv_out <- search_pv(query = query, fields = fields, all_pages = TRUE)
dl <- unnest_pv_data(data = pv_out$data, pk = "patent_number")
```
```{r echo=FALSE}
top_asgns <- dl$assignees %>%
filter(!is.na(assignee_organization))
top_asgns <- mutate(top_asgns, ttl_pats = as.numeric(assignee_total_num_patents))
top_asgns <- group_by(top_asgns, assignee_organization, ttl_pats)
top_asgns <- summarise(top_asgns, db_pats = n())
top_asgns <- mutate(top_asgns, frac_db_pats = round(db_pats / ttl_pats, 3))
top_asgns <- ungroup(top_asgns)
top_asgns <- select(top_asgns,c(1, 3, 2, 4))
top_asgns <- arrange(top_asgns,desc(db_pats))
top_asgns <- slice(top_asgns, c(1:75))
```
Row
-----------------------------------------------------------------------
### Top Assignes
```{r}
# Create datatable:
datatable(
data = top_asgns,
rownames = FALSE,
colnames = c("Assignee", "AV patents","Total patents",
"AV patents / total patents"),
caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: left; font-style: italic;',
"Table 1: Top assignees in 'Autonomous Vehicles'"
),
options = list(pageLength = 10)
)
```
### Hchart

Row
-----------------------------------------------------------------------
### Citation Network
```{r}
percent_rank2 <- function(x)
(rank(x, ties.method = "average", na.last = "keep") - 1) / (sum(!is.na(x)) - 1)
# Create a data frame with normalized citation rates and stats from Step 2:
asng_p_dat <-
dl$patents %>%
mutate(patent_yr = substr(patent_date, 1, 4)) %>%
group_by(patent_yr) %>%
mutate(perc_cite = percent_rank2(patent_num_cited_by_us_patents)) %>%
inner_join(dl$assignees) %>%
group_by(assignee_organization) %>%
summarise(mean_perc = mean(perc_cite)) %>%
inner_join(top_asgns) %>%
arrange(desc(ttl_pats)) %>%
filter(!is.na(assignee_organization)) %>%
slice(1:20) %>%
mutate(color = "#f1c40f") %>%
as.data.frame()
kable(head(asng_p_dat), row.names = FALSE)
```
### Citation Network 2
```{r}
```
Scientometric
=======================================================================
```{r include=FALSE}
library(bibliometrix)
library(treemap)
library(tm)
library(pander)
library(knitr)
Dtisi <- readFiles("~/MEGA/IMTOOL2/IMtool2/data/savedrecs.bib")
database <- convert2df(Dtisi, dbsource = "isi", format = "bibtex")
dfbiblio <- biblioAnalysis(database, sep = ";")
df.summary <- summary(object = dfbiblio, k = 10, pause = FALSE)
```
Row
-----------------------------------------------------------------------
### Top Articles
```{r}
knitr::kable(df.summary$MostCitedPapers)
```
### Most Productive Countries
```{r}
knitr::kable(df.summary$TCperCountries, align = 'c')
```
Row
-----------------------------------------------------------------------
### Most Relevant Sources
```{r}
knitr::kable(df.summary$MostRelSources)
```
### Most Related Keyword
```{r}
knitr::kable(df.summary$MostRelKeywords)
```
Trends
=======================================================================
```{r include=FALSE}
library(gtrendsR)
library(forecast)
library(tseries)
keyword = c("Healthcare innovation", "Healthcare Technologies")
res = gtrends(keyword)
keyword_pt = "Inovações em Saúde"
res_pt = gtrends(keyword_pt)
gt.fc.en <- res$interest_over_time
fc.en <- forecast(res$hits)
xt_en <- window(gt.fc.en[,2],end=218)
xf_en <- window(gt.fc.en[,2],start=219)
```
Row
-----------------------------------------------------------------------
### Google Trends World
```{r}
plot(res)
```
### Forecast analysis - EN
```{r}
rwd_en <- rwf(xt_en,drift=T,h=25)
plot(rwd_en,main="Random Walk with Drift Method",ylab="Level",xlab="Tseries")
lines(gt.fc.en[,2])
```
Row
-----------------------------------------------------------------------
### Google Trends - Brasil
### Forecast Analysis - Brazil
News
=======================================================================
Row
-----------------------------------------------------------------------
### Google News
### Yahoo News
Row
-----------------------------------------------------------------------
### geom_density and facet_wrap Together
```{r}
```
### Density and Scatterplot Overlay Using geom_density
```{r}
```
OECD
=======================================================================
Row
-----------------------------------------------------------------------
### stat_density Example
```{r}
```
### Add Conditional Density Curves to Plot
```{r}
```
Row
-----------------------------------------------------------------------
### geom_density and facet_wrap Together
```{r}
```
### Density and Scatterplot Overlay Using geom_density
```{r}
```
EUROSTAT
=======================================================================
```{r include=FALSE}
library(eurostat)
library(rvest)
# Check Id
id <- search_eurostat("Passenger cars, by alternative motor energy and by power of vehicles",type = "dataset")$code[1]
# Download Dataset
dat <-get_eurostat(id, time_format = "num", type = "label")
dat <- data.frame(dat)
# Subset by type of energy
elec <- subset(dat, prod_nrg == "Electrical Energy", select = c(geo, time, values))
gas <- subset(dat, prod_nrg == "Natural Gas", select = c(geo, time, values))
lpg <- subset(dat, prod_nrg == "LPG", select = c(geo, time, values))
other <- subset(dat, prod_nrg == "Other products", select = c(geo, time, values))
total <- subset(dat, prod_nrg == "Total", select = c(geo, time, values))
# Total analysis
el.date <- aggregate(values ~ time, elec, sum)
gas.date <- aggregate(values ~ time, gas, sum)
lpg.date <- aggregate(values ~ time, lpg, sum)
other.date <- aggregate(values ~ time, other, sum)
total.date <- aggregate(values ~ time, total, sum)
```
Row
-----------------------------------------------------------------------
### Sector Investment
```{r}
# Plot by Sector/Years
p <- plot(el.date, type='o',
col="red",
ylab="Amount of Eur(millions)",
xlab="Years",
ylim = c(0, 10000))
points(values ~ time, data=gas.date, type='b', col="green")
points(values ~ time, data=lpg.date, type='l',lty=2, col="blue")
points(values ~ time, data=other.date, type='l', col="orange")
title(main="Investiment in Automotive Sector in UE", col.main="black", font.main=4)
legend("topleft",
c("Electric", "Gas", "Lpg", "Other"),
lty = c(1,1,1,1),
col = c("red", "green", "blue", "orange"))
```
### Countries Analisys
```{r}
# Dendogram
total.geo <- aggregate(values ~ geo, total, sum)
dd <- dist(scale(total.geo$values), method = "euclidean")
name <- as.factor(total.geo$geo)
hc <- hclust(dd, method = "ward.D2")
plot(hc)
```
Row
-----------------------------------------------------------------------
### geom_density and facet_wrap Together
```{r}
```
### Density and Scatterplot Overlay Using geom_density
```{r}
```
Trends Series (BETS)
=======================================================================
Row
-----------------------------------------------------------------------
### stat_density Example
```{r}
```
### Add Conditional Density Curves to Plot
```{r}
```
Row
-----------------------------------------------------------------------
### geom_density and facet_wrap Together
```{r}
```
### Density and Scatterplot Overlay Using geom_density
```{r}
```
Social Media
=======================================================================
```{r include=FALSE}
consumer_key <- 'YetGrrFzoeN0UUQfCZoQERsYg'
consumer_secret <- 'xb2sXMwcLOP5HNERJBgPw2gCHUPjSSFy0VLhRScgJjfkCaP79K'
access_token <- '293631173-p2Kv4K7BW41D0vNXc5OQgdBR5nCwR4D7pmiiTgyh'
access_secret <- 'JpO4Wik99qyREddOfi0zdnxhsUdhhv1PhjbL52i4gqoHv'
library(httr)
library(devtools)
library(twitteR)
library(base64enc)
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
tweets <- searchTwitter("autonomous vehicles",n=300,lang="en")
tweets_df = twListToDF(tweets)
library(tm)
mycorpus = Corpus(VectorSource(tweets_df$text))
mycorpus = tm_map(mycorpus, stripWhitespace)
mycorpus = tm_map(mycorpus, tolower)
mycorpus = tm_map(mycorpus, removePunctuation)
# keep a copy for stem completion later
myCorpusCopy <- mycorpus
dtm <- DocumentTermMatrix(mycorpus)
freq <- colSums(as.matrix(dtm))
ord <- order(freq,decreasing=TRUE)
freq[head(ord)]
tdm <- TermDocumentMatrix(mycorpus,
control = list(wordLengths = c(1, Inf)))
term.freq <- rowSums(as.matrix(tdm))
term.freq <- subset(term.freq, term.freq >= 20)
df <- data.frame(term = names(term.freq), freq = term.freq)
```
Row
-----------------------------------------------------------------------
### Common words
```{r echo=FALSE}
library(ggplot2)
ggplot(df, aes(x=term, y=freq)) + geom_bar(stat="identity") +
xlab("Terms") + ylab("Count") + coord_flip() +
theme(axis.text=element_text(size=7))
```
### Wordcloud
Row
-----------------------------------------------------------------------
### geom_density and facet_wrap Together
```{r}
```
### Density and Scatterplot Overlay Using geom_density
```{r}
```
Survey
=======================================================================
```{r}
```
Row
-----------------------------------------------------------------------
### Sector Investment
```{r}
```
### Countries analysis
```{r}
```
Row
-----------------------------------------------------------------------
### geom_density and facet_wrap Together
```{r}
```
### Density and Scatterplot Overlay Using geom_density
```{r}
```
Start-up monitoring
=======================================================================
Row
-----------------------------------------------------------------------
### stat_density Example
```{r}
```
### Add Conditional Density Curves to Plot
```{r}
```
Social Media
Row
Common words
Wordcloud
Row
geom_density and facet_wrap Together
Density and Scatterplot Overlay Using geom_density