RSS Feed!

Recent Posts

Recent Comments




Archive for February, 2014

ggplot2 Color Consistency

Tuesday, February 11th, 2014

I use the ggplot2 package in R for graphics in the analysis I perform for my clients.  In my current project I am analyzing the performance of 3 systems as compared to a base rate model.  Some of the charts include the base rate and a ground truth series, some exclude the base rate and some exclude the ground truth.  By the nature of the alphabetical ordering of the names for the systems, base rate, and ground truth, the color for a given system may be different on different charts.  It’s a minor thing, but consistency is better than inconsistency.  The answer is to use the scale_colour_manual and scale_fill_manual commands in ggplot2 to set the colors.  I have several lists of color settings, one for each combination that I wish to plot, wherein the color for a given system is consistent across settings.  Then, when I want to use the color settings I add a statement like “+ scale_colour_manual(values=’allSystemColors’)” to my ggplot command.

I found the page <> to be a handy reference to visually link the name of the color to the color itself.