library(gtrendsR)
library(dplyr)
library(ggplot2)
library(plotly)
library(scales)
gg_trends <- function(keyword){
output <- gtrends(keyword,
gprop = "web",
geo = "US-DE",
time = "2020-01-01 2021-02-28",
onlyInterest = TRUE)
output_interest <- output$interest_over_time
output_interest$date <- as.Date(output_interest$date)
ggplotly(
ggplot(data = output_interest,
aes(y = hits,
x = date,
color = keyword)) +
geom_line() +
scale_x_date(date_labels = "%b %y") +
theme_minimal()
) %>%
layout(width = 1000, height = 400)
}
eviction_kw <- c("eviction",
"eviction + tenant lawyer + tenant attorney",
"eviction + landlor lawyer + landlord attorney",
"eviction + eviction lawyer + eviction attorney")
gg_trends(eviction_kw)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
housing_kw <- c("eviction",
"low income housing + affordable housing + short term housing",
"motel",
"voucher")
gg_trends(housing_kw)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
general_kw <- c("eviction",
"moratorium",
"foreclosure")
gg_trends(general_kw)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
foreclosure_kw <- c("foreclosure",
"foreclosure listing + foreclosure listings + foreclosure sale + foreclosure sales",
"sheriff sale + sheriff sales",
"mortgage loan + mortgage loans")
gg_trends(foreclosure_kw)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
lease_kw <- c("break lease")
gg_trends(lease_kw)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
foreclosure_assistance_kw <- c("forebearance",
"housing assistance",
"refinance + refinancing + refinance rates + refinance calculator",
"foreclosure")
gg_trends(foreclosure_assistance_kw)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()