I have simple data frame that I want to visualize with a treemap. I've made using ggplot
and treemapify
. It seems ok, but I am wondering how can I show both name and lab variables inside the treemap without showing one as a label and one in the legend .
Here is dummay sample and my try:
library(ggplot2)
library(treemapify)
data <-
data.frame(
name = c("Group A", "Group B", "Group C", "Group D"),
value = c(8, 22, 66, 4),
lab = c("8%", "22%", "66%", "4%")
) %>%
mutate(lab = as.factor(lab))
ggplot(data, aes(area = value, fill = lab, label = name)) +
geom_treemap() +
geom_treemap_text(
colour = "white",
place = "centre",
size = 15,
) +
scale_fill_brewer(palette = "Greens")