Domanda

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.

È stato utile?

Soluzione 2

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

Altri suggerimenti

treemapify is a ggplot2 solution, as you were hoping for.

https://github.com/wilkox/treemapify

And the results are beautiful & flexible - typical of ggplot2 and its extensions.

enter image description here

You are looking for treemap:

require(treemap)
treemap(data,c("group","stock"),"mvalue",vColor="Perf",type="value")

enter image description here

This example from the treemap package is also helpful:

data(GNI2010)
treemap(GNI2010,
        index=c("continent", "iso3"),
        vSize="population",
        vColor="GNI",
        type="value")

Using the search term "treemap" you will find more information, e.g., http://en.wikipedia.org/wiki/Treemap

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top