For the past several years I’ve regularly consumed Pantoprazole – a proton pump inhibitor (PPI) – to control my acid reflux. However, as it is well know, regular PPI use causes various health problems. I’ll not enumerate those here, but trust me when I say that they are numerous. Last year I decided to wean myself off PPIs slowly, by only limiting to a 20mg dose on any single day, and alternating or dropping some days completely. I recorded my dosage information in Google calendar on my mobile, so that I could process it later. Now that I’ve a more than a year’s data with me I thought of visualizing it to get an understanding of my dosage habits.
Getting the Google calendar data in a usable format was the first challenge. Thankfully I found an online service – calendarlabs.com – that allowed me to easily download the data in a CSV format.
The kind of visualization I had in mind was like the following heatmap. Although my visualization would only display the day with a filled square where I had taken a PPI.
As I wanted to use R for visualizing the data, the nearest package I found was the Calendar Heatmap code by Paul Bleicher.
The first step in generating the chart was to read the CSV file containing the daily dosage data.
> pan.data <- read.csv("gcal-p.csv")
# A few sample rows from the data file
> head(pan.data)
dosage date
1 1 2018-1-1
2 1 2018-1-4
3 1 2018-1-7
4 1 2018-1-8
5 1 2018-1-9
6 1 2018-1-10
We need the Calendar code to generate the chart. We can download it in our current directory and use it or just use the online version.
> source("https://raw.githubusercontent.com/iascchen/VisHealth/master/R/calendarHeat.R")
The code will load additional libraries – lattice, grid and chron, so make sure those are installed.
Now with the data loaded we just run the calendar code to generate the yearly chart as shown below.
> calendarHeat(pan.data$date, pan.data$dosage, varname="Pan 20 dosage",color = "w2b")
calendarHeat() function takes the following options.
date: Dates for which the data needs to be plotted.
values: Values associated with those dates.
color: The color palette. Default is r2g (red to green). Other predefined options are r2b (red to blue) and w2b (white to blue). You can create your own palette by defining a vector as shown below.
ncolors: Number of colors for the heatmap
varname: Title for the chart
calendarHeat(pan.data$date, pan.data$dosage, varname="Pan 20 dosage",color = "r2g")
The colors of the grid can be changed from the given three styles –
r2b #red to blue
r2g #red to green
w2b #white to blue
g2r #green to red