嵌套甜甜圈图进行比较

时间:2019-07-18 10:10:13

标签: r ggplot2 ggplotly

我正在尝试制作两个甜甜圈图以比较一些指标。数据帧如下,

ImageView bart = (ImageView) findViewById(R.id.bart);
bart.animate().alpha(0).setDuration(2000);

因此,两个图应分别代表ImageViewbart列,但行[instance].animate()...应取自new_sum var `1` `2` <dbl> <chr> <dbl> <dbl> 1 98.7 cnt_alerts 45.1 NA 2 98.7 cnt_incidents_total 15.6 NA 3 98.7 sum_of_events 100 NA 4 100 cnt_alerts NA 44.4 5 100 cnt_incidents_total NA 16.2 6 100 sum_of_events NA 100 列。因此最后,这两个图将如下所示(尝试使用绘画进行复制)

enter image description here

数据

1

1 个答案:

答案 0 :(得分:2)

像这样吗?

library(tidyverse)
df1 %>% 
  mutate(
    id = rep(1:2, each = 3),
    value = coalesce(`1`, `2`),
    value = ifelse(var == "sum_of_events", new_sum, value)
  ) %>% 
  ggplot(aes(var)) + 
  geom_col(aes(y = 100), position = 'identity', fill = 'white', col = 1, width = 0.5) +
  geom_col(aes(y = value), position = 'identity', fill = 'grey60', col = 1, width = 0.5) +
  facet_grid(~id) +
  coord_polar(theta = 'y') +
  theme_minimal()

enter image description here