Search code examples
rggplot2treemapquantitative-finance

Performance Clustermap in R


I found this very appealing chart about the performance of the S&P500 from the WSJ.:

http://s.wsj.net/public/resources/images/MI-CA398B_STOCK_G_20131230184809.jpg

I'm trying to recreate it in R but I have no idea how to best plot the data, eg

data<-data.frame(stock=c("A","B","C","D"),group=c(rep("Fin",2),rep("Ind",2)),Perf=rnorm(4,0,1),mvalue=abs(rnorm(4,100,50)))

Has anybody a idea how to recreate it (e.g. with ggplot2?) or has anybody ever done a similar plot? Thx in advance.


Solution

  • Or portfolio:

    require(portfolio)
    
    dt<-data.frame(ticker=paste0(sample(LETTERS,100,T),sample(LETTERS,100,T),sample(LETTERS,100,T)),
               value=abs(rnorm(100,10000,4000)),
               perc_change=rnorm(100,0,0.1),
               group=sample(LETTERS[1:4],100,T)
                   )
    
    rownames(dt)
    
    map.market(dt$ticker,lab=c(T,T), area=dt$value, group=dt$group, color=dt$perc_change, main="Stock Map")
    

    enter image description here