Learn R Programming

treemapify (version 2.3.1.9001)

treemapify_fixed: Generate coordinates for a treemap with a fixed 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.

Unlike the treemapify function, treemapify_fixed does not use the squarified layout algorithm to minimise tile aspect ratio. Instead it uses the striped algorithm, which can result in some tiles with poor aspect ratios (long and skinny), but has the advantage that the position of tiles is fixed by their order in the data frame. This allows for side-by-side comparisons or animated treemaps showing change over time. Tile placement proceeds by filling columns from left to right, beginning at the bottom of each column.

Usage

treemapify_fixed(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

"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, geom_treemap

Other treemapify: treemapify