Search code examples
rdata-visualizationtreemap

treemap for no hierarchical data


I am new in R. I have a scenario, may be you can give me some hints.

I have a very simple vector:

dt<-c(4.94 , 4.84 , 2.89)

I would like to have a main square, with the area of 4.94, and then in this area the second square 4.84. Third square with the area of 2.89 should be in the second square (4.84)

How can I do this in R?


Solution

  • areas <- c(4.94 , 4.84 , 2.89) #vector of areas
    sides <- sqrt(areas) #vectors of side lengths
    
    plot(0,0,type="n",xlim=c(0,4),ylim=c(0,4),axes=F,ann=F, asp=1) #Blank plot
    rect(0,0,sides,sides,col=1:3,border=1:3)
    

    ![enter image description here

    or centered:

    plot(0,0,type="n",xlim=c(-2,2),ylim=c(-2,2),axes=F,ann=F, asp=1) #Blank plot
    rect(-sides/2,-sides/2,sides/2,sides/2,col=1:3,border=1:3)
    

    ![enter image description here

    Is this what your looking for?