Skip to contents

Lays out one rectangle per value inside the box [x, x + width] x [y, y + height], with area proportional to the value and aspect ratios kept close to 1. Returns rectangles in the original input order.

Usage

treemap_layout(values, x = 0, y = 0, width = 1, height = 1)

Arguments

values

Non-negative numeric vector (one per tile). Zero / negative values produce zero-area tiles.

x, y

Lower-left corner of the bounding box. Default 0.

width, height

Bounding box size. Default 1.

Value

A data frame with columns xmin, xmax, ymin, ymax, one row per input value, in input order.

Examples

treemap_layout(c(6, 3, 2, 1))
#>        xmin      xmax ymin ymax
#> 1 0.0000000 0.5000000  0.0  1.0
#> 2 0.5000000 1.0000000  0.0  0.5
#> 3 0.5000000 0.8333333  0.5  1.0
#> 4 0.8333333 1.0000000  0.5  1.0