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:
- Manually download the images you want to plot
- Load the images, save them to a list, using readPNG()
- Make a table of color frequency for each flag
- Wrangle those tables into a dataframe of color frequencies by flag, ordered by color
- Plot them with ggplot2, using color names both as “breaks” and as “values”