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”

*Related*

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 on topics such as:

Data science,

Big Data, R jobs, visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...

**Tags:** ggplot2, graphics, MASS, png, reshape, rstats