質問

How can i create treemap with only two colors(red(-ve) and green(+ve)) exactly. I am currently using tmPlot and here follows my sample data and sample code.

index vSize vColor
S1    100    1
S2    150   -1
S3    125    1
S4    267   -1 

     svg("sample.svg")
     library(treemap)
     tmPlot(data,c("index"),"vSize","vColor","comp")
     dev.off()

Thanks in Advance

役に立ちましたか?

解決

So do you actually want two fixed colors, i.e. two categories, or do you still want the numeric scale?

In the first case, the code is:

library(treemap)
data <- data.frame(index=paste0("S",1:4), vSize=c(100,150,125,267),
                   vColor=factor(c(1,-1,1,-1)))
treemap(data,c("index"), "vSize", "vColor", "categorical")

For this 'categorical' treemap I factorized the vColor variable. You can assign any fixed colors you like with the argument palette.

Best, Martijn

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top