You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ggplot2/2021-08-04-treemaps.Rmd
-8
Original file line number
Diff line number
Diff line change
@@ -31,8 +31,6 @@ library(ggplot2)
31
31
32
32
p <- ggplot(G20, aes(area = gdp_mil_usd, fill = hdi)) +
33
33
geom_treemap()
34
-
35
-
p
36
34
```
37
35
38
36
This plot isn’t very useful without the knowing what country is represented by each tile. `geom_treemap_text()` can be used to add a text label to each tile. It uses the `ggfittext` package to resize the text so it fits the tile. In addition to standard text formatting aesthetics you would use in `geom_text()`, like fontface or colour, we can pass additional options specific for `ggfittext`. For example, we can place the text in the centre of the tile with place = "centre", and expand it to fill as much of the tile as possible with grow = TRUE.
@@ -52,8 +50,6 @@ p <- ggplot(G20, aes(area = gdp_mil_usd, fill = hdi, label = country)) +
52
50
geom_treemap() +
53
51
geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
54
52
grow = TRUE)
55
-
56
-
p
57
53
```
58
54
59
55
Note that several tiles in the top right corner have no labels. `geom_treemap_text()` will hide text labels that cannot fit a tile without being shrunk below a minimum size, by default 4 points. This can be adjusted with the min.size argument.
@@ -77,8 +73,6 @@ p <- ggplot(G20, aes(area = gdp_mil_usd, fill = hdi, label = country,
geom_treemap_text(colour = "white", place = "topleft", reflow = T)
80
-
81
-
p
82
76
```
83
77
Up to three nested levels of subgrouping are supported with the subgroup2 and subgroup3 aesthetics. Borders and text labels for these subgroups can be drawn with `geom_treemap_subgroup2_border()`, etc. Note that `ggplot2` draws plot layers in the order that they are added. This means it is possible to accidentally hide one layer of subgroup borders with another. Usually, it’s best to add the border layers in order from deepest to shallowest, i.e. `geom_treemap_subgroup3_border()` then `geom_treemap_subgroup2_border()` then `geom_treemap_subgroup_border()`.
0 commit comments