Last active
May 5, 2021 16:46
-
-
Save madilk/bdd175e6d1b83ab7eba521e1f0f4ef8b to your computer and use it in GitHub Desktop.
ggcorrrplot - correlation plot in R with Google Analytics data
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
library(googleAnalyticsR) | |
ga_auth(json_file = "C:\\folder-where-your-json-is-located\\service-key.json") | |
account_list$viewId | |
#pls change id | |
id <- 1234567 | |
data <- google_analytics(id, | |
date_range = c("2021-01-01","2021-05-02"), | |
metrics=c("sessions","bounceRate", | |
"pageviewsPerSession", | |
"users","goal1Completions"), | |
dimensions = c("date","dayOfWeek"), | |
anti_sample = TRUE) | |
) | |
View(data) | |
#install package | |
#http://www.sthda.com/english/wiki/ggcorrplot-visualization-of-a-correlation-matrix-using-ggplot2 | |
install.packages("ggcorrplot") | |
library(ggcorrplot) | |
corr <- round(cor(data[ , c(3:7)]),1) | |
#display correlation in console | |
Corr | |
#ggcorrplot | |
ggcorrplot(corr,lab=TRUE) | |
#ggcorrplot with circle | |
ggcorrplot(corr,method="circle",lab=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment