Distribution of colors by flag

October 22, 2012
By

(This article was first published on is.R(), and kindly contributed to R-bloggers)

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”

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: , , , , ,

Comments are closed.

Recent popular posts

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Dommino data lab

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series





Six Sigma Online Training





Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)