rajibc
rajibc

Reputation: 93

Treemapify subgroup label

I need to understand why the label aesthetics is throwing an error while I draw the treemap. My data looks as below:

> head(samplecellband)
 identity    band           rsrp_cat         rsrq_cat    N rsrpdist rsrqdist                            rsrprsrq
1: 486(alpha) 2300-c1 Cell Edge-Coverage     Good-Quality 3422    15447    24408     Cell Edge-Coverage+Good-Quality
2: 486(alpha) 2300-c1 Cell Edge-Coverage Marginal-Quality 1849    15447     5816 Cell Edge-Coverage+Marginal-Quality
3: 486(alpha) 2300-c1      Good-Coverage     Good-Quality  340     4674    24408          Good-Coverage+Good-Quality
4: 486(alpha) 2300-c1  Marginal-Coverage Marginal-Quality  332     7634     5816  Marginal-Coverage+Marginal-Quality
5: 486(alpha) 2300-c1 Cell Edge-Coverage     Poor-Quality  126    15447      859     Cell Edge-Coverage+Poor-Quality
6: 486(alpha) 2300-c1      Poor-Coverage     Poor-Quality  209     3777      859          Poor-Coverage+Poor-Quality
 rsrprsrq_total rsrprsrq_total_pcnt
1:          11204                  36
2:           3809                  12
3:           4563                  14
4:            745                   2
5:            341                   1
6:            468                   1

and my code is as below:

library(treemapify)
ggplot(samplecellband, aes(area = N, subgroup=rsrprsrq, fill=rsrprsrq)) +
  geom_treemap() +
  geom_treemap_text(colour = "white", place = "top", reflow = T,
                    aes(label=band), alpha = 0.5) +
  geom_treemap_subgroup_border(colour="red") +
  geom_treemap_subgroup_text(
    place = "bottom", padding.y = grid::unit(5, "mm"),
    grow = T, colour = "black", min.size = 0, 
    aes(label = paste(rsrprsrq,"\n",rsrprsrq_total," ( ",rsrprsrq_total_pcnt,"%)"))) +
  facet_wrap(~identity)

This throws me an error:

**Warning: Ignoring unknown aesthetics: label**

I do get the output as below, but I need to put labels and data in the subgroup.

treemap

I guess the label aesthetics in the geom_treemap_subgroup_text is causing this ... any lead to the right direction how to achieve the same?

Thanks.

Upvotes: 1

Views: 886

Answers (1)

Kim
Kim

Reputation: 4328

I'm not 100% sure that this is the output that you want, but feeding the label you want directly as the subgroup argument seems to be the right direction.

ggplot(samplecellband, 
       aes(area = N, subgroup = paste0(rsrprsrq, "\n", rsrprsrq_total, 
                                       " ( ", rsrprsrq_total_pcnt, "%)"), 
           fill = rsrprsrq, label = band)) +
  geom_treemap() +
  geom_treemap_text(colour = "white", place = "top", reflow = T,
                    aes(label = band), alpha = 0.5) +
  geom_treemap_subgroup_border(colour = "red") +
  geom_treemap_subgroup_text(
    place = "bottom", padding.y = grid::unit(5, "mm"),
    grow = T, colour = "black", min.size = 0) +
  facet_wrap(~identity)

Each input partition then effectively contains both labels.

Upvotes: 1

Related Questions