Learn R Programming

treemapify (version 2.3.1)

treemapify: Generate coordinates for a treemap with a squarified layout

Description

Takes a data frame of observations, with variables mapped to area and fill colour, and produces the coordinates for a treemap expressing these observations and mappings. These coordinates can be used to draw a customised treemap (recommended) or passed directly to the "ggplotify" function to produce an exploratory projection.

Input data frame must be in tidy format (see article by Hadley Wickham, below), i.e. each row must represent a single observation and each column a single variable. The area and fill parameters are mandatory; grouping and label factors are optional. Note that while adding a label will not change the treemap layout, adding a group will, as observations from the same group will be kept together.

Tile placement proceeds from the bottom left corner, alternating between moving rightwards and moving upwards. See Bruls et al. 1999 for the full algorithm. For a tile layout in which the position of tiles is fixed by their order in the input data frame, see treemapify_fixed.

Usage

treemapify(data, area, fill, group, label, xlim = c(0, 100), ylim = c(0,
  100))

Arguments

data

a tidy data frame, containing at least variables to be mapped to area (size of tile) and fill (fill colour of tile).

area

variable to be mapped to area; must be a column in data

fill

variable to be mapped to fill; must be a column in data

group

(optional) variable to be mapped to group; must be a column in the data frame

label

(optional) variable to be used as the label for each observation; must be a column in the data frame

xlim, ylim

(optional) two-element vectors specifying the x and y limits of the area in which the tiles will be placed

References

treemapify uses the Squarified Treemap algorithm of Mark Bruls, Kees Huizing and Jarke van Wijk:

Bruls, M., Huizing, K., & van Wijk, J. (1999). Squarified Treemaps (pp. 33-42). Presented at the In Proceedings of the Joint Eurographics and IEEE TCVG Symposium on Visualization. http://www.win.tue.nl/~vanwijk/stm.pdf

"Tidy Data" is described by Hadley Wickham in: Wickham, H. (2014). Tidy data. Journal of Statistical Software. https://www.jstatsoft.org/article/view/v059i10/v59i10.pdf

See Also

treemapify_fixed, geom_treemap

Other treemapify: ggplotify, treemapify_fixed