SYTYCD — where are these terrific dancers come from?

June 29, 2012
By

(This article was first published on Tony's bubble universe » R, and kindly contributed to R-bloggers)

It’s Saturday midnight and I’m already sleepy. However, after several hours, I finally got this google geographic map embedded in my post. Aha!!!

This is about 20 finalists from the 9th season of So You Think You Can Dance. I count the states where they come from. Then plot the numbers on US map. Here shows the map.

SYTYCD2012
Data: dat • Chart ID: SYTYCD2012
R version 2.15.0 (2012-03-30) • googleVis-0.2.15Google Terms of UseData Policy

Dancers’ names would show up when hovering on the map. Excuse me for not including Daniel Baker, the Australian ballet dancer. The code is also provided.

?View Code RSPLUS
1
2
3
4
5
6
7
8
9
10
11
loc <- read.table("clipboard", sep = "\t", colClasses = "character")  
colnames(loc) <- c("name", "home")
loc$home <-  gsub("^\\w.+\\,\\s", "", loc$home)  # remove cities
state <- split(loc$name, f = loc$home)
dat <- data.frame(sapply(state, paste, collapse = ", "), sapply(state, length))
colnames(dat) <- c("names", "count") 
dat$state <- rownames(dat)
g.dat <- gvisGeoMap(dat, locationvar = "state", numvar = "count", 
                    hovervar = "names", 
                    options = list(region = "US"), chartid = "SYTYCD2012")
cat(unlist(g.dat$html), file = "distribution.html")  # map code used here

To leave a comment for the author, please follow the link and comment on his blog: Tony's bubble universe » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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.