Tuesday, October 28, 2014

Treemaps in R

Following the directions from: http://flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/

I learned:
  • data <- read.csv("http://datasets.flowingdata.com/post-data.txt")install.packages("portfolio")
  • library(portfolio)
  • map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map")
So basically, I learned how to read in data from the Flowing Data website, how to install (and re-install--> dev.off() ) packages, and then the Treemap tutorial worked. Pretty awesome. 

This is the longer version of what happened:

> map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map")

Hit <Return> to see next plot: 
Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) : 
  invalid graphics state
> dev.off()
null device 
          1 
> data <- read.csv("http://datasets.flowingdata.com/post-data.txt")
> install.packages("portfolio")
Error in install.packages : Updating loaded packages
> library(portfolio)
> map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map")

Restarting R session...

Loading required package: sp
> install.packages("portfolio")
trying URL 'http://cran.rstudio.com/bin/macosx/contrib/3.1/portfolio_0.4-6.tgz'
Content type 'application/x-gzip' length 1413591 bytes (1.3 Mb)
opened URL
==================================================
downloaded 1.3 Mb

Now to edit a CSV file with data that is interesting.



No comments:

Post a Comment