Search code examples
rggplot2treemap

How to set same size for label text of treemap in ggplot2


I have plot a treemap using the following code:

library(treemap)
library(ggplot2)
ggplot2::ggplot(G20, ggplot2::aes(area = gdp_mil_usd, fill = econ_classification,label = country), size = 4) +
  geom_treemap() +
  geom_treemap_text(grow = T, reflow = T, colour = "black", place = "centre", family = "STKaiti", size = 4)

Out:

enter image description here

Now I wonder if it's possible to set the label text with same size, I have added parameter size = 4 in ggplot() and geom_treemap_text(), but it didn't works.

Anyone could help to deal with this issue? Thanks.


Solution

  • Set grow=FALSE in geom_treemap_text.

    library(treemapify)
    library(ggplot2)
    ggplot2::ggplot(G20, ggplot2::aes(area = gdp_mil_usd, 
                   fill = econ_classification, label = country)) +
      geom_treemap() +
      geom_treemap_text(grow = F, reflow = T, colour = "black", 
                        place = "centre", family = "STKaiti", size = 14)
    

    enter image description here