Two ways to do this are either using a heatmap or the calendar chart/calendar heatmap from the Google Charts API. I am sure that there are other ways to visualize data like this. Note that you will probably need to do a preliminary aggregation to the date
, user_id
level using mean
.
Heatmap:
This works particularly well when you have multiple variables.
library(gtools)
library(ClassDiscovery)
library(devtools)
# install_github('googleVis', 'mages')
library(googleVis)
#==========================================================
# 1. multiple variables; heatmap
#==========================================================
# generate sequence of dates
vDates = seq.Date(from = as.Date('29-11-2012',
format = '%d-%m-%Y'),
length.out = 203, by = 'day')
# generate the random samples
dfHeatMap = as.matrix(rdirichlet(length(vDates), runif(15)))
row.names(dfHeatMap) = as.character(vDates)
# adjust column labels for neater plotting
vDatesNew = rep(as.Date(NA), length(vDates))
vDatesNew[seq(from = 1, to = 203, by = 10)] =
vDates[seq(from = 1, to = 203, by = 10)]
# adjust row labels for neater plotting
labRow = c(NA, NA, 3, NA, NA, 6, NA, NA, 9,
NA, NA, 12, NA, NA, 15)
# draw the heatmap with aspect control
png('heatmap.png', height = 900, width = 1200, pointsize = 16)
aspectHeatmap(t(dfHeatMap), Rowv = NA, Colv = NA,
col = cm.colors(256), labCol = vDatesNew, labRow = labRow,
margins = c(5, 5), hExp = 1.5, wExp = 4, cex.lab = 2)
dev.off()
Calendar heatmap:
This uses the Google Charts API for calendar charts. I took some of the configurations for this from here. An almost identical static version of this can be found here.
#==========================================================
# 2. calendar chart from google charts API via googleVis
# NOTE: this handles only one variable
# NOTE: http://lamages.blogspot.in/2014/04/calendar-charts-with-googlevis.html
#==========================================================
dfHeatMap2 = data.frame(heatValue = runif(length(vDates)),
dates = vDates)
print(
gvisCalendar(data=dfHeatMap2, datevar="dates", numvar="heatValue",
options=list(
title="Randomly generated proportion variable",
calendar="{cellSize:10,
yearLabel:{fontSize:20, color:'#444444'},
focusedCellColor:{stroke:'red'}}",
width=1600, height=1200),
), file = 'something.html', tag = 'chart')