문제

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