set.seed(1789)
N <- 20
area <- rlnorm(N)
PlotTreemap(x=sort(area, decreasing=TRUE), labels=letters[1:20], col=Pal("RedToBlack", 20))
grp <- sample(x=1:3, size=20, replace=TRUE, prob=c(0.2,0.3,0.5))
z <- Sort(data.frame(area=area, grp=grp), c("grp","area"), decreasing=c(FALSE,TRUE))
z$col <- SetAlpha(c("steelblue","green","yellow")[z$grp],
unlist(lapply(split(z$area, z$grp),
function(...) LinScale(..., newlow=0.1, newhigh=0.6))))
PlotTreemap(x=z$area, grp=z$grp, labels=letters[1:20], col=z$col)
b <- PlotTreemap(x=z$area, grp=z$grp, labels=letters[1:20], labels.grp=NA,
col=z$col, main="Treemap")
# the function returns the midpoints of the areas
# extract the group midpoints from b
mid <- do.call(rbind, lapply(lapply(b, "[", 1), data.frame))
# and draw some visible text
BoxedText( x=mid$grp.x, y=mid$grp.y, labels=LETTERS[1:3], cex=3, border=NA,
col=SetAlpha("white",0.7) )
Run the code above in your browser using DataLab