Type Package Title Treemap visualization Version 1.1-1 Date 2012-07-10 Author Martijn Tennekes Package treemap February 15, 2013 Maintainer Martijn Tennekes <mtennekes@gmail.com> A treemap is a space-filling visualization of hierarchical structures. With this package different kind of treemaps can be generated, such as comparison treemaps and density treemaps. Small multiples are also supported. License GPL-3 LazyLoad yes Depends grid, RColorBrewer, data.table Collate basetreemap.r cat2col.r comp2col.r createrec.r datasets.r dens2col.r drawlegend.r index2col.r linked2c Repository CRAN Date/Publication 2012-07-10 11:05:40 NeedsCompilation no R topics documented: treemap-package...................................... 2 GNI2010.......................................... 3 sbsdata........................................... 3 tmclick........................................... 3 tmlocate.......................................... 4 tmplot............................................ 4 Index 11 1
2 treemap-package treemap-package Treemap visualization Package: treemap Type: Package Version: 1.1-1 Date: 2012-07-10 License: GPL-3 LazyLoad: yes Details A treemap is a space-filling visualization of hierarchical structures. With this package different kind of treemaps can be generated, such as comparison treemaps and density treemaps. Small multiples are also supported. The function tmplot is used to plot treemaps. The functions tmclick and tmlocate are used to respectively capture a mouse click on a treemap and locate the corresponding object. Author(s) Martijn Tennekes <mtennekes@gmail.com> References Shneiderman, B, Plaisant, C (2009) Treemaps for space-constrained visualization of hierarchies. Website Tennekes, M., Jonge, E. de (2011) Top-down data analysis with treemaps. Proceedings of the International Conference on Information Visualization Theory and Applications, IVAPP 2011, Algarve, Portugal. Examples # load Gross national income data data(gni2010) # create treemap tmplot(gni2010, index=c("continent", "iso3"), vsize="population", vcolor="gni", type="value")
GNI2010 3 GNI2010 GNI 2010 Data Gross national income (per capita) in dollars per country in 2010. References Website of The World Bank - Health Nutrition and Population Statistics sbsdata Structural Business Statistics Data Fictive structural business statistics data of 2008 and 2009. tmclick Mouse capture Captures a mouse click and convert it to npc coordinates. Such coordinates are needed for tmlocate Usage tmclick()
4 tmplot tmlocate Returns info about clicked rectangle This function returns information about the object on which user has clicked. Usage tmlocate(npcclick, tmsave) Arguments npcclick tmsave mouse click in npc coordinates, which can be generated by tmclick treemap information: value returned by tmplot Examples data(sbsdata) ## Not run: tmsave <- vsize=c("employees09", "value added09", "turnover09", "salaries09"), vcolor=c("employees08", "value added08", "turnover08", "salaries08"), type="comp") # capture mouseclick npcclick <- tmclick() # locate clicked object print(tmlocate(npcclick, tmsave)) ## End(Not run) tmplot Create treemap Create treemap
tmplot 5 Usage tmplot(dtf, index, vsize, vcolor = NULL, type = "value", title = NA, subtitle = NA, algorithm = "pivotsize", sortid = "-size", palette = NA, range = NA, vcolorrange = NULL, fontsize.title = 14, fontsize.labels = 11, fontsize.legend = 12, lowerbound.cex.labels = 0.4, inflate.labels = FALSE, bg.labels = ifelse(type %in% c("value", "linked", "categorical"), "#CCCCCCAA", NA), force.print.labels = FALSE, position.legend = ifelse(type %in% c("categorical", "index"), "right", ifelse(type == "linked", aspratio = NA, na.rm = FALSE) Arguments dtf index vsize vcolor type title subtitle algorithm a data.frame. Required. vector containing the column names in dtf that contain the aggregation indices. Required. name of the variable that determines the sizes of the rectangles. For small multiples, a vector of variable names (one for each treemap) should be given. Required. name of the variable that, in combination with type, determines the colors of the rectangles. The variable can be scaled by the addition of "*<scale factor>" or "/<scale factor>". For small multiples, a vector of variable names (one for each treemap) should be given. the type of the treemap: "value": the vcolor-variable is directly mapped to a color palette (by default Brewer s diverging color palette "RdBu"). "comp": colors indicate change of the vsize-variable with respect to the vcolorvariable in percentages. Note: the negative scale may be different from the positive scale in order to compensate for the ratio distribution. "dens": colors indicate density. This is aanalogous to a population density map where vsize-values are area sizes, vcolor-values are populations per area, and colors are computed as densities (i.e.\ population per squared km s). "linked": each object has a distinct color, which can be useful for small multiples (objects are linked by color) "index": each aggregation level (defined by index) has a distinct color "categorical": vcolor is a categorical variable that determines the color title of the treemap. For small multiples, a vector of titles should be given. Titles are used to describe the sizes of the rectangles. subtitle of the treemap. For small multiples, a vector of subtitles should be given. Subtitles are used to describe the colors of the rectangles. name of the used algorithm: "squarified" or "pivotsize". The squarified treemap algorithm (Bruls et al., 2000) produces good aspect ratios, but ignores the sorting order of the rectangles (sortid). The ordered treemap, pivot-by-size, algorithm (Bederson et al., 2002) takes the sorting order (sortid) into account while aspect ratios are still acceptable.
6 tmplot Value sortid palette range vcolorrange name of the variable that determines the order in which the rectangles are placed from top left to bottom right. Also the values "size" and "color" can be used. To inverse the sorting order, use "-" in the prefix. By default, large rectangles are placed top left. For small multiples, a vector of variable names (one for each treemap) can be given. Only applicable when algortihm=="pivotsize". either a color palette or a name of a Brewer palette (see display.brewer.all()). A Brewer palette can be reversed by prefixing its name with a "-". range of values that determine the colors. When omitted, the range of actual values is used. This range is mapped to palette. deprecated, use range instead. fontsize.title (maximum) font size of the title fontsize.labels font size(s) of the data labels, which can be: one number, which specifies the font size for all aggregation levels vector of two numbers, which specific the font sizes for 1) the highest and 2) the other aggregation levels vector of three numbers, which specific the font sizes for 1) the highest, 2) any in-between, and 3) the lowest aggregation level. fontsize.legend (maximum) font size of the legend lowerbound.cex.labels multiplier between 0 and 1 that sets the lowerbound for the data label font sizes: 0 means draw all data labels, and 1 means only draw data labels if they fit at fontsize.data. inflate.labels logical that determines whether data labels are inflated inside the rectangles. bg.labels background color of labels of high aggregation levels. If set to NA, the color is determined by the color of the underlying rectangle. For value, categorical and linked treemaps, the default is transparent grey ("#CCCCCCAA"), and for the other types, NA. force.print.labels logical that determines whether data labels are being forced to be printed (also when they don t fit). position.legend position of the legend: "bottom", "right", or "none". For categorical and index treemaps, "right" is the default value, for linked treemap, "none", and for the other types, "bottom". aspratio na.rm A list is silently returned: preferred aspect ratio of the main rectangle, defined by width/height. When set to NA, the available window size is used. logical that determines whether missing values are omitted during aggregation tm list with for each treemap a data.frame containing information about the rectangles
tmplot 7 nrow ncol vsize vcolor number of rows in the treemap grid number of rows in the treemap grid argument vsize argument vcolor This list can be used to locate a mouse click (see tmlocate). References Bederson, B., Shneiderman, B., Wattenberg, M. (2002) Ordered and Quantum Treemaps: Making Effective Use of 2D Space to Display Hierarchies. ACM Transactions on Graphics, 21(4): 833-854. Bruls, D.M., C. Huizing, J.J. van Wijk. Squarified Treemaps. In: W. de Leeuw, R. van Liere (eds.), Data Visualization 2000, Proceedings of the joint Eurographics and IEEE TCVG Symposium on Visualization, 2000, Springer, Vienna, p. 33-42. Examples ### quick example ### ### data: Gross national income data # load Gross national income data data(gni2010) # create treemap tmplot(gni2010, index=c("continent", "iso3"), vsize="population", vcolor="gni", type="value") ### extended examples ### ### data: fictive structural business statistics data ### load fictive structural business statistics data data(sbsdata) sbsdata$employees.growth <- sbsdata$employees09 - sbsdata$employees08 ### types # value treemap: the color variable is directly mapped to the colors
8 tmplot vcolor="employees.growth", type="value") # comparisson treemaps: colors indicate change of vsize with respect to vcolor vcolor="employees08", type="comp") # four comparisson treemaps vsize=c("employees09", "value added09", "turnover09", "salaries09"), vcolor=c("employees08", "value added08", "turnover08", "salaries08"), type="comp") # density treemaps: colors indicate density (like a population density map) vsize="turnover09", vcolor="employees09*1000", type="dens") vcolor="turnover09", type="dens") # linked treemaps: objects are linked by color over different treemaps tmplot(sbsdata[sbsdata$section=="manufacturing",], index="subsection", vsize=c("income09", "employees09", "expenditures09", "salaries09"), type="linked") # index treemap: each aggregation index has distinct color type="index") # categorical treemap: colors are determined by a categorical variable vcolor="section", type="categorical")
tmplot 9 ### layout algorithm vcolor="employees.growth", type="value", algorithm="squarified") ### graphical options: fontsize # draw labels at fixed fontsize (fit only) vcolor="employees08", type="comp", fontsize.labels=12, lowerbound.cex.labels=1) # draw labels at flexible fontsize (skip tiny rectangles) vcolor="employees08", type="comp", fontsize.labels=12, lowerbound.cex.labels=.6) # draw labels at maximal fontsize vcolor="employees08", type="comp", fontsize.labels=10, lowerbound.cex.labels=1, inflate.labels = TRUE) # draw all labels at fixed fontsize vcolor="employees08", type="comp", fontsize.labels=10, lowerbound.cex.labels=1, force.print.labels=true)
10 tmplot ### graphical options: color palette # terrain colors sbsdata$employees.growth <- sbsdata$employees09 - sbsdata$employees08 vcolor="employees.growth", type="value", palette=terrain.colors(10)) # Brewer s Red-White-Grey palette reversed with predefined range vcolor="employees.growth", type="value", palette="-rdgy", range=c(-20000,20000))
Index Topic treemap treemap-package, 2 GNI2010, 3 sbsdata, 3 tmclick, 2, 3, 4 tmlocate, 2, 3, 4, 7 tmplot, 2, 4, 4 treemap (treemap-package), 2 treemap-package, 2 11