How to create color-coded calendars in R

Posted on 11-01-2019 , by: admin , in , 0 Comments

A color-coded calendar can be a quick and easy way to see whether you’re achieving a daily goal. Did you meet a daily business metric like sales or social-media posts? Or, how are you doing with personal goals, like exercising every day? With one glance, you can get a feel for how you’ve been doing. It’s great for tracking those New Year’s resolutions—and a whole lot more.

R can help. For this example, I’ll create a calendar that tracks daily exercise—more specifically, whether you did cardio, did strength training, or rested each day.

You need to get your data before you can visualize it. For simple manual data entry, I usually use Microsoft Excel or Google Sheets. (As much of an R enthusiast as I am, R generally isn’t ideal for data entry.) 

One way to set up the spreadsheet is with two columns: one for Day and another for Activity. What I don’t want to do, however, is enter freeform text into a column where R expects specific categories. Even if I’ll remember that the exact format for strength training is “strength training” and not “weights,” there’s always the risk of typos. So, I suggest either creating a form for spreadsheet data entry or adding data validation to the category column (in this case, Activity).

Data options column Sharon Machlis/IDG

Acceptable data-entry options in Excel

For a task like this, I prefer data validation instead of complicating things with a separate form. An easy way to set up the validation is to create a column of acceptable options in another tab—in this case, Cardio and Strength Training. Next, select the cells where you want to restrict data entry—in this case, the whole Activity row except for the header.

Then choose Data Validation in the Excel data ribbon and select list, and enter the cells with the acceptable options in the source field. Now you can enter the data you want to use in R.