Distribution of colors by flag

A story: We showed you how to use R to assess flag similarity and make a scatter plot of raster images. Dr. Wickham referred us to the set of 2400 flag icons made available by GoSquared, and then (probably jokingly) challenged us to replicate the cool plot of color-by-flag pie charts made by Shahee Ilyas.

Of course, we accepted the challenge, but I wanted to avoid the pie chart bugaboo, and share the code so anyone could do the same (which is just what we do here at is.R())

The code is a little more complicated than most of our projects, but essentially follows these steps:

  1. Manually download the images you want to plot
  2. Load the images, save them to a list, using readPNG()
  3. Make a table of color frequency for each flag
  4. Wrangle those tables into a dataframe of color frequencies by flag, ordered by color
  5. Plot them with ggplot2, using color names both as “breaks” and as “values”

By d-sparks

Tags: rstats graphics png reshape ggplot2 MASS