| Title: | Make Treemap Bar Charts with 'ggplot2' |
|---|---|
| Description: | Provides 'ggplot2' geoms analogous to 'geom_col()' and 'geom_bar()' that allow for treemaps using 'treemapify' nested within each bar segment. Also provides geometries for subgroup bordering and text annotation. |
| Authors: | Harry Thompson [aut, cre, cph] |
| Maintainer: | Harry Thompson <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0.9000 |
| Built: | 2026-05-22 18:48:44 UTC |
| Source: | https://github.com/hrryt/ggtreebar |
ggplot2 geoms analogous to ggplot2::geom_bar() and ggplot2::geom_col()
that allow for treemaps like with treemapify::geom_treemap()
nested within each bar segment.
geom_treebar( mapping = NULL, data = NULL, stat = "count", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", ... ) geom_treecol( mapping = NULL, data = NULL, stat = "identity", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", ... )geom_treebar( mapping = NULL, data = NULL, stat = "count", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", ... ) geom_treecol( mapping = NULL, data = NULL, stat = "identity", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
Override the default connection between |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
fixed |
Deprecated. Use |
layout |
The layout algorithm, one of either 'squarified' (the default), 'scol', 'srow' or 'fixed'. See Details for full details on the different layout algorithms. |
start |
The corner in which to start placing the tiles. One of 'bottomleft' (the default), 'topleft', 'topright' or 'bottomright'. |
... |
Other arguments passed on to
|
data is split by all aesthetics except for the subgroup aesthetics.
A treemap is then drawn using treemapify::treemapify() from each section
of the data, inheriting its aesthetics, and using the subgroup aesthetics
to determine hierarchy.
geom_treebar() understands the following aesthetics
(required aesthetics are in bold):
x
y
alpha
colour
fill
linetype
linewidth
subgroup
subgroup2
subgroup3
geom_treecol() understands the following aesthetics
(required aesthetics are in bold):
x
y
alpha
colour
fill
linetype
linewidth
subgroup
subgroup2
subgroup3
Learn more about setting these aesthetics in vignette("ggplot2-specs").
stat_count() understands the following aesthetics
(required aesthetics are in bold):
x or y
group
weight
Learn more about setting these aesthetics in vignette("ggplot2-specs").
These are calculated by the 'stat' part of layers and can be accessed with delayed evaluation.
after_stat(count)
number of points in bin.
after_stat(prop)
groupwise proportion
geom_treebar_subgroup_border(), geom_treebar_subgroup_text().
library(ggplot2) ggplot(diamonds, aes(clarity, fill = cut, subgroup = color)) + geom_treebar() ggplot(diamonds, aes(y = cut, fill = color, subgroup = clarity)) + geom_treebar(position = "dodge")library(ggplot2) ggplot(diamonds, aes(clarity, fill = cut, subgroup = color)) + geom_treebar() ggplot(diamonds, aes(y = cut, fill = color, subgroup = clarity)) + geom_treebar(position = "dodge")
Add borders to subgroups of a treemap bar chart generated by
geom_treebar() or geom_treecol().
geom_treebar_subgroup_border( mapping = NULL, data = NULL, stat = "count", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treecol_subgroup_border( mapping = NULL, data = NULL, stat = "identity", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treebar_subgroup2_border(...) geom_treecol_subgroup2_border(...) geom_treebar_subgroup3_border(...) geom_treecol_subgroup3_border(...)geom_treebar_subgroup_border( mapping = NULL, data = NULL, stat = "count", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treecol_subgroup_border( mapping = NULL, data = NULL, stat = "identity", position = "stack", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treebar_subgroup2_border(...) geom_treecol_subgroup2_border(...) geom_treebar_subgroup3_border(...) geom_treecol_subgroup3_border(...)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
fixed |
Deprecated. Use |
layout |
The layout algorithm, one of either 'squarified' (the default), 'scol', 'srow' or 'fixed'. See Details for full details on the different layout algorithms. |
start |
The corner in which to start placing the tiles. One of 'bottomleft' (the default), 'topleft', 'topright' or 'bottomright'. |
level |
One of 'subgroup', 'subgroup2' or 'subgroup3', giving the
subgrouping level for which to draw borders. It is recommended to use the
aliases |
... |
Other arguments passed on to
|
These functions take the same aesthetic mappings as geom_treebar() and
geom_treecol(), and are to be used in conjunction with them, ensuring that
arguments like position match where supplied.
geom_treebar(), geom_treebar_subgroup_text().
library(ggplot2) ggplot(diamonds, aes(y = clarity, fill = color, subgroup = color, subgroup2 = cut)) + geom_treebar(position = "dodge") + geom_treebar_subgroup_border(position = "dodge", linewidth = 2)library(ggplot2) ggplot(diamonds, aes(y = clarity, fill = color, subgroup = color, subgroup2 = cut)) + geom_treebar(position = "dodge") + geom_treebar_subgroup_border(position = "dodge", linewidth = 2)
Add text labels to subgroups of a treemap bar chart generated by
geom_treebar() or geom_treecol().
geom_treebar_subgroup_text( mapping = NULL, data = NULL, stat = "count", position = "stack", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(1, "mm"), place = "bottom", min.size = 4, grow = FALSE, reflow = FALSE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treecol_subgroup_text( mapping = NULL, data = NULL, stat = "identity", position = "stack", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(1, "mm"), place = "bottom", min.size = 4, grow = FALSE, reflow = FALSE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treebar_subgroup2_text(...) geom_treecol_subgroup2_text(...) geom_treebar_subgroup3_text(...) geom_treecol_subgroup3_text(...)geom_treebar_subgroup_text( mapping = NULL, data = NULL, stat = "count", position = "stack", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(1, "mm"), place = "bottom", min.size = 4, grow = FALSE, reflow = FALSE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treecol_subgroup_text( mapping = NULL, data = NULL, stat = "identity", position = "stack", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(1, "mm"), place = "bottom", min.size = 4, grow = FALSE, reflow = FALSE, fixed = NULL, layout = "squarified", start = "bottomleft", level = "subgroup", ... ) geom_treebar_subgroup2_text(...) geom_treecol_subgroup2_text(...) geom_treebar_subgroup3_text(...) geom_treecol_subgroup3_text(...)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
Override the default connection between |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
padding.x, padding.y
|
|
place |
Where inside the box to place the text. Default is |
min.size |
Minimum font size, in points. If provided, text that would need to be shrunk below this size to fit the box will not be drawn. Defaults to 4 pt. |
grow |
If |
reflow |
If |
fixed |
Deprecated. Use |
layout |
The layout algorithm, one of either 'squarified' (the default), 'scol', 'srow' or 'fixed'. See Details for full details on the different layout algorithms. |
start |
The corner in which to start placing the tiles. One of 'bottomleft' (the default), 'topleft', 'topright' or 'bottomright'. |
level |
One of 'subgroup', 'subgroup2' or 'subgroup3', giving the
subgrouping level for which to draw text labels. It is recommended to use
the aliases |
... |
Other arguments passed on to
|
These functions take the same aesthetic mappings as geom_treebar() and
geom_treecol(), and are to be used in conjunction with them, ensuring that
arguments like position match where supplied.
geom_treebar(), geom_treebar_subgroup_border().
library(ggplot2) ggplot(diamonds, aes(y = clarity, fill = cut, subgroup = color)) + geom_treebar(position = "dodge") + geom_treebar_subgroup_text(position = "dodge")library(ggplot2) ggplot(diamonds, aes(y = clarity, fill = cut, subgroup = color)) + geom_treebar(position = "dodge") + geom_treebar_subgroup_text(position = "dodge")