# Distribution of colors by flag

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**is.R()**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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”

To

**leave a comment**for the author, please follow the link and comment on their blog:**is.R()**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.