**OUseful.Info, the blog... ยป Rstats**, and kindly contributed to R-bloggers)

In London Olympics 2012 Medal Tables At A Glance? I posted some treemap visualisations of the Olympics medal tables generated using a Google Visualisation Chart treemap component. I thought it might be worth posting a quick R generated example too, using the off-the-shelf/straight out of CRAN treemap component. (If you want to play along, download the data as CSV from here.)

The original data looks like this:

but ideally we want it to look like this:

I posted a quick recipe showing how to do this sort of reshaping in Google Refine, but in R it’s even easier – just melt the Gold, Silver and Bronze columns into a pair of columns…

Here’s the full code to do the reshaping and generate a simple treemap:

#load in the data from a file odata = read.csv("~/Downloads/nbc_olympic_medalscrape.csv") #Reshape the data require(reshape) odatar=melt(odata,id=c('cc','ccevent','Event')) #And generate the treemap in the simplest possible way require(treemap) tmPlot(odatar, index=c("cc", "Event","variable"), vSize="value", vColor='value', type="value")

And here’s the treemap:

Generating variant views (I described six variants in the original post) is easy enough – just tweak the order of the elements of the `index` setting. (I should have named the melt created columns something more sensible than the default, shouldn’t I? Note that the `vSize` and `vColor` *value* value (sic) refers to the column name that identifies the medalType column. The `type` *value* says use the numerical value…. (i.e. it’s literal – it doesn’t refer to a column name…)

Out of the can – simples enough… So what might we be able to do with a little bit more treatment? Examples via the comments, please ๐

**leave a comment**for the author, please follow the link and comment on their blog:

**OUseful.Info, the blog... ยป Rstats**.

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...