Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

charts Treemap with ggplots and treemapify

$
0
0

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")

The treemap graph : enter image description here

I am trying to have a graph like this example enter image description here


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>