Вопрос

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