Last active
February 27, 2021 17:01
-
-
Save madilk/074f6598b49cfe60bb46aaac51c6ff46 to your computer and use it in GitHub Desktop.
gganimate plot using google analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://code.markedmondson.me/googleAnalyticsR/articles/setup.html | |
install.packages("googleAnalyticsR") | |
library(googleAnalyticsR) | |
#change location to your service key folder | |
ga_auth(json_file = "C:\\location-folder-for your-service-account-json\\service-key.json") | |
account_list <- ga_account_list() | |
account_list$viewId | |
#change view id to your GA view | |
ga_id <- 1234567 | |
data <- google_analytics(ga_id, | |
date_range = c("2019-01-01", "2020-11-30"), | |
metrics = "sessions", | |
dimensions = c("date","channelGrouping"), | |
anti_sample = TRUE) | |
head(data) | |
summary(data) | |
install.packages("gganimate") | |
library(gganimate) | |
#https://gganimate.com/articles/gganimate.html | |
#transition_reveal params http://search.r-project.org/library/gganimate/html/transition_reveal.html | |
p <- ggplot(subset(data,channelGrouping=="Organic Search"), | |
aes(x=date,y=sessions, | |
colour=channelGrouping)) + | |
geom_line() + | |
transition_reveal(date) + | |
theme(legend.position = "bottom") + | |
ggtitle("Daily Organic Search Traffic to AnalyticsLog.com") | |
p | |
#https://stackoverflow.com/questions/51440496/using-gganimate-to-export-gif | |
anim_save("organic search.gif",p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p <- ggplot(subset(data,channelGrouping=="Organic Search"), | |
aes(x=date,y=sessions, | |
colour=channelGrouping)) + | |
geom_line() + | |
transition_reveal(date) + | |
theme(legend.position = "bottom") + | |
ggtitle("Daily Organic Search Traffic to AnalyticsLog.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment