This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(gtrendsR)
## Warning: package 'gtrendsR' was built under R version 4.4.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
trend <- gtrends(keyword = c("Shopee", "Tokopedia", "Bukalapak"),
geo = "ID",
time = "today 12-m")
df_time <- trend$interest_over_time %>%
select(date, hits, keyword) %>%
mutate(hits = as.numeric(ifelse(hits == "<1", 0, hits)))
df_region <- trend$interest_by_region %>%
filter(location != "") %>%
group_by(keyword) %>%
mutate(hits = as.numeric(ifelse(hits == "<1",0, hits)))
You can also embed plots, for example:
ggplot(df_region, aes(x = reorder(location, hits), y = hits, fill = keyword)) +
geom_bar(stat = "identity", position = "dodge") +
coord_flip() +
labs(title = "Minat Berdasarkan Provinsi",
x = "Provinsi", y = "Tren (0-100)") +
theme_minimal()
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.