This site is intended to be a resource for digital analysts who are interesting to learn or expand their knowledge of R and statistics. That’s from whence the semi-silly name came from:
(Clearly, this is not a site about “branding an initiative” or “coming up with a totally awesome name for a site!”)
Our hope is that, for the analyst who is new to R, by going through the resources on this site, the code and output below will start to make some real sense!
This example shows a visualization of traffic to a site broken down by day of week and hour of day.
library(highcharter)
library(googleAnalyticsR)
library(reshape2)
library(forecast)
view_id <- 81416156
ga_auth()
gadata <- google_analytics_4(view_id,
date_range = c(Sys.Date() - 400, Sys.Date()),
metrics = "sessions",
dimensions = c("date","hour"),
max = -1)
gadata$weekday <- ordered(weekdays(gadata$date, FALSE),
levels = c("Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday"))
heatmap_data <- gadata[, c("weekday","hour","sessions")]
heatmap_recast <- dcast(heatmap_data, weekday ~ hour, sum)
heatmap_matrix <- as.matrix(heatmap_recast[-1])
row.names(heatmap_matrix) <- c("Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday")
## heatmap of weekdays per hour
hchart(heatmap_matrix, type = "heatmap")
Long gone (can) be the days of forecasting simply by dropping a trendline on some data. This example uses the Holt-Winters method to apply some smoothing and seasonality to the base data to build a forecast that includes the likely range of values.
gadata2 <- google_analytics_4(view_id,
date_range = c("2013-08-01", "2016-07-31"),
metrics = "sessions",
dimensions = c("yearMonth"),
max = -1)
ga_ts <- ts(gadata2$sessions, start = c(2013,08), end = c(2016,07), frequency = 12)
forecast1 <- HoltWinters(ga_ts)
## forecast for next 12 months of the blog sessions
hchart(forecast(forecast1, h = 12))