Treemapify子组标签

时间:2018-04-20 03:30:32

标签: r ggplot2

我需要理解为什么标签美学在绘制树形图时会抛出错误。我的数据如下所示:

> 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

我的代码如下:

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)

这引发了一个错误:

**Warning: Ignoring unknown aesthetics: label**

我确实得到如下输出,但我需要在子组中放置标签和数据。

treemap

我认为geom_treemap_subgroup_text中的标签美学导致了这一点......任何导致正确方向如何实现同样的目标?

感谢。

1 个答案:

答案 0 :(得分:1)

我并非100%确定这是您想要的输出,但直接将您想要的标签作为subgroup参数提供似乎是正确的方向。

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)

然后,每个输入分区都有效地包含两个标签。