【发布时间】:2021-12-16 19:00:20
【问题描述】:
我有以下数据框,我用它来使用下面给出的代码创建图表 -
数据 -
```structure(list(percents = c(52, 40, 34, 55, 48, 38, 17), label = c("Type 1",
"Type 2", "Type 3", "Type 4", "Type 5", "Type 6", "Type 7")), class = "data.frame", row.names = c(NA,
-7L))```
```df %>% mutate(r = sqrt(percents), x = r + cumsum(lag(2 * r, default = 0))) %>%
ggplot() +
geom_circle(aes(x0 = x, r = r, y0 = r), size = 3, color = "gray") +
geom_text(aes(x = x, y = r, label = paste0(percents, "%"), size = percents),
fontface = "bold", color = "#643291") +
geom_text(aes(x = x, y = 20, label = label), vjust = 0,
fontface = "bold", color = "gray20", size = 3) +
geom_segment(aes(x = x, xend = x, y = r + 3, yend = 18),
color = "#643291", size = 2) +
coord_equal() +
scale_y_continuous(limits =c(-5, 25)) +
scale_size_continuous(range = c(4, 8)) +
theme_void() +
theme(legend.position = "none") +
labs(title ='2018')```
Then I have the following data for 2018 group B -
```structure(list(percents = c(48, 60, 66, 45, 52, 62, 83), label = c("Type 1",
"Type 2", "Type 3", "Type 4", "Type 5", "Type 6", "Type 7")), class = "data.frame", row.names = c(NA,
-7L))```
```df %>% mutate(r = sqrt(percents), x = r + cumsum(lag(2 * r, default = 0))) %>%
ggplot() +
geom_circle(aes(x0 = x, r = r, y0 = r), size = 3, color = "black") +
geom_text(aes(x = x, y = r, label = paste0(percents, "%"), size = percents),
fontface = "bold", color = "#643291") +
geom_text(aes(x = x, y = 20, label = label), vjust = 0,
fontface = "bold", color = "gray20", size = 3) +
geom_segment(aes(x = x, xend = x, y = r + 3, yend = 18),
color = "#643291", size = 2) +
coord_equal() +
scale_y_continuous(limits =c(-5, 25)) +
scale_size_continuous(range = c(4, 8)) +
theme_void() +
theme(legend.position = "none") +
labs(title ='2018')```
我的问题是,有没有一种方法可以重叠这两个图表,以像我现在所做的那样将两个线性圆圈集一起显示与并排显示?
谢谢!
【问题讨论】:
-
我将不胜感激任何形式的回应!谢谢!
-
您希望最终产品看起来像什么?你想要一排 14 个圆圈,你想要两个单独的面板一起显示,你想要每种类型的圆圈重叠吗?无论如何,最好将您的数据集与
bind_rows(a, b, .id = "source")之类的东西合并为一个。 -
感谢您的宝贵时间!我希望圆圈与一个共同的中点重叠。
标签: r ggplot2 encryption data-visualization bubble-chart