O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To create treemap, follow these steps:

  1. First, create a dataframe that has three branches, each branch containing several subbranches and each subbranch with a value that we map to an area:
> branch=c(rep("branch-1",4),rep("branch-2",2),rep("brach-3",3))> subbranch=paste("subbranch" , c(1,2,3,4,1,2,1,2,3), sep="-")> value=c(13,5,22,12,11,7,3,1,23)> data=data.frame(branch,subbranch,value)
  1. Next, draw the plot and specify the levels in the order of importance- branch > subbranch > sub-subbranch through the index argument:
> treemap(data,index=c("branch","subbranch"),vSize="value",type="index" )

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required