user3488736 user3488736 - 1 month ago 17
R Question

Tips needed with plotting a subset of google trends data

I'm just new with R-programming and Google Trends, so forgive me for this basic question. I successfully acquired some google trends data from a tutorial like this:

library(gtrendsR)
library(methods)
usr <- "<usr>"
psw <- "<psw>"
gconnect(usr, psw)
lang_trend <- gtrends(c("pga", "nhl", "nba", "nfl"))
plot(lang_trend)


I get a nice plot for all 4 terms.
enter image description here
Now I'd like to know how to just plot the data for just nba for example

Thanks in advance!

Answer

This could help get you started. From the documentation of the gtrendsR package: lang_trend is "An object of class ‘gtrends’ which is list with six elements containing the results. "

    library(gtrendsR)
    library(methods)
    usr <- "<usr>"
    psw <- "<pwd>"
    gconnect("<usr>", "<pwd>") 
    lang_trend <- gtrends(c("pga", "nhl", "nba", "nfl"))
    plot(lang_trend$trend[ ,"start"], lang_trend$trend[,"nba."], type = "lines")
Comments