2
$\begingroup$

I have a two column table consisting of: date, user_id.
I'd like to visualize a grid with date along the x axis, and user_id along the y.
If date, user_id exists, I'd like to show a grid with a color, say green.
If date, user_id does not exist, I'd like to show a grid in white.
Bonus points if date, user_id shows up multiple points resulting in a darker green color.

What tool, preferably free and online, is best suited to visualize these data in the manner I've described? Follow up question: which other tools are good at visualizing time series data of user events as a calendar? Something like: https://developers.google.com/chart/interactive/docs/gallery/calendar

$\endgroup$

1 Answer 1

4
$\begingroup$

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()

enter image description here

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')

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.