Showing posts with label ggplot2. Show all posts
Showing posts with label ggplot2. Show all posts

Wednesday, December 03, 2014

Creating your own Google Trends plots in R

With this post, I want to demonstrate how you can use the R functions I've built to create your own Google Trends graphs.



First, install the functions by pasting this code into R.

You now have the following functions at your disposal:
  • URL_GT(keywords)
  • downoloadGT(url, downloadDir)
  • readGT(file path)
By running the following code, you will get chart above.

#downloadDir=Where you save the csv from Google Trends
downloadDir="C:/downloads"
setwd(downloadDir)
keywords=c("Samsung", "Apple", "Nokia")
url=URL_GT(keywords)
filePath=downloadGT(url, downloadDir)
smartphones=readGT(filePath)

library(ggplot2)

ggplot(smartphones, aes(x=Date, y=SVI, color=Keyword))+geom_line()
Entertaining Blogs - BlogCatalog Blog Directory
Bloggtoppen.se