Skip to content

Commit b871583

Browse files
committed
fix treemap images
1 parent 0fec8d3 commit b871583

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

ggplot2/2021-08-04-treemaps.Rmd

-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ library(ggplot2)
3131
3232
p <- ggplot(G20, aes(area = gdp_mil_usd, fill = hdi)) +
3333
geom_treemap()
34-
35-
p
3634
```
3735

3836
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)) +
5250
geom_treemap() +
5351
geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
5452
grow = TRUE)
55-
56-
p
5753
```
5854

5955
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,
7773
geom_treemap_subgroup_text(place = "centre", grow = T, alpha = 0.5, colour =
7874
"black", fontface = "italic", min.size = 0) +
7975
geom_treemap_text(colour = "white", place = "topleft", reflow = T)
80-
81-
p
8276
```
8377
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()`.
8478

@@ -107,8 +101,6 @@ p <- ggplot(G20, aes(area = 1, label = country, subgroup = hemisphere,
107101
) +
108102
geom_treemap_subgroup3_text(place = "top", colour = "blue", alpha = 0.5) +
109103
geom_treemap_text(colour = "white", place = "middle", reflow = T)
110-
111-
p
112104
```
113105

114106
As demonstrated, there is no assurance that the resulting plot will look good.

0 commit comments

Comments
 (0)