r - Ggplot2:按类别表示比例的气泡?
问题描述
我有这个数据:
# A tibble: 19 x 8
country Prop_A Prop_B Prop_C Prop_D Prop_E Prop_F Prop_G
<fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Austria 1 1 0.912 0.912 0.518 0.999 0.567
2 Belgium 1 1 0.821 1 0.687 0.0990 0.925
3 Denmark NA NA NA NA NA NA NA
4 France 0.750 1 0.361 0.345 0 0.0658 0.563
5 Germany 0.928 1 0.674 0.783 0.128 0.635 0.0828
6 Greece 0 1 0 0 0 1 0
7 Hungary 0.812 1 0.812 0.812 0 0.375 0.188
8 Israel 1 1 1 0.755 0.450 0.241 0.292
9 Italy 0.962 1 0.881 0.516 0.533 0 0.0230
10 Latvia 0 1 1 0 0 0 0
11 Lithuania 0.507 1 1 0.507 0 0 0
12 Malta 1 1 1 1 0 1 0
13 Netherlands 0.818 1 1 0.682 0.5 0.182 0.682
14 Portugal 0.829 1 1 0.829 0 0.610 0.509
15 Romania 1 1 1 1 0 0.273 1
16 Spain 1 1 1 0.787 0.215 0.191 0.653
17 Sweden 0.792 1 0.792 0.167 0.375 0 0
18 Switzerland 0.697 1 1 0.547 0.126 0.724 0.210
19 Turkey 1 1 0.842 0.775 0.585 0.810 0.117
>
0.812 代表匈牙利提案 A 的 81% (7)
我想要的是这种图形:
https://zupimages.net/viewer.php?id=20/13/ob6z.png
我想在泡沫中有“81%”,在行中有国家,在列中有不同的“道具”。
我试过geom_tile,但没有用。我不明白我的数据是否构建得不好,或者我只是没有找到好的命令。
感谢您的帮助 !
解决方案
这是制作气泡图的一种方法。
library(tidyverse)
df %>%
mutate_at(vars(starts_with("Prop")), list(~. * 100)) %>%
pivot_longer(cols = starts_with("Prop"), names_to = c("Prop", "Type"), names_sep = "_") %>%
ggplot(aes(x = Type, y = country, size = value, label = value)) +
geom_point(shape = 21, fill = "white") +
geom_text(size = 3) +
scale_size(range = c(5, 15), guide = F)
阴谋
推荐阅读
- python - 创建键值类
- r - 根据R中的逻辑条件插入列
- c# - 如何使用 c#.net 中的 datatimepicker 获取月份更改后的月份数
- go - 无限循环通道操作导致高 CPU 使用率
- android - 在使用 kotlin 的 Volley 调试中使用 GET 请求
- security - openid 连接 2.0 并在仅 http cookie 中设置身份验证 JWT
- git - Azure DevOps 构建中的“在 .gitmodules 中找不到子模块路径的 url”错误
- python - 在带有 random.sample 的 for 循环中没有重复
- mysql - MySQL 事件不起作用(插入语句)
- android - 如何在android导航中使用单顶