ggalluvial - 让层的顺序遵循数据集
ggalluvial - let order of stratums follow dataset
我已经搜索并查看了类似(可能相同)问题的其他答案,但老实说,我没有得到相应的答案,因为我绝对不喜欢 R。
我基本上想做的是展示所有 Arm 架构和它们的实现(处理器)之间的关系,以及它们关于“配置文件”的家族分组。所以我有 4 个轴:配置文件、系列、架构和处理器。
我从维基百科 (https://en.wikipedia.org/wiki/List_of_ARM_microarchitectures) 中获取数据并将其输入 excel 以便能够将其导入 R-Studio(再次:我刚刚安装了 R 和 R-Studio 并且完全没有使用这种语言和工具的经验)。我保留了“顺序”,所以基本上我只是在 Excel 中复制了 table 以便能够在 R-Studio 中导入数据。
> head(ARM)
# A tibble: 6 × 4
Profil Familie Architektur Prozessor
<chr> <chr> <chr> <chr>
1 Classic ARM1 ARMv1 ARM1
2 Classic ARM2 ARMv2 ARM2
3 Classic ARM2 ARMv2a ARM250
4 Classic ARM3 ARMv2a ARM3
5 Classic ARM6 ARMv3 ARM60
6 Classic ARM6 ARMv3 ARM600
完整数据:
> dput(ARM)
structure(list(Profil = c("Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Microcontroller",
"Classic", "Microcontroller", "Microcontroller", "Microcontroller",
"Microcontroller", "Microcontroller", "Microcontroller", "Microcontroller",
"Microcontroller", "Microcontroller", "Microcontroller", "Microcontroller",
"Realtime", "Realtime", "Realtime", "Realtime", "Realtime", "Realtime",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application"), Familie = c("ARM1", "ARM2", "ARM2", "ARM3", "ARM6",
"ARM6", "ARM6", "ARM7", "ARM7", "ARM7", "ARM7T", "ARM7T", "ARM7T",
"ARM7T", "ARM7EJ", "ARM8", "ARM9T", "ARM9T", "ARM9T", "ARM9T",
"ARM9E", "ARM9E", "ARM9E", "ARM9E", "ARM9E", "ARM10E", "ARM10E",
"ARM10E", "ARM11", "ARM11", "ARM11", "ARM11", "SecurCore", "SecurCore",
"SecurCore", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex"), Architektur = c("ARMv1", "ARMv2", "ARMv2a",
"ARMv2a", "ARMv3", "ARMv3", "ARMv3", "ARMv3", "ARMv3", "ARMv3",
"ARMv4T", "ARMv4T", "ARMv4T", "ARMv4T", "ARMv5TEJ", "ARMv4",
"ARMv4T", "ARMv4T", "ARMv4T", "ARMv4T", "ARMv5TE", "ARMv5TE",
"ARMv5TE", "ARMv5TEJ", "ARMv5TE", "ARMv5TE", "ARMv5TE", "ARMv5TEJ",
"ARMv6", "ARMv6T2", "ARMv6Z", "ARMv6K", "ARMv6-M", "ARMv4T",
"ARMv7-M", "ARMv6-M", "ARMv6-M", "ARMv6-M", "ARMv7-M", "ARMv7E-M",
"ARMv7E-M", "ARMv8-M Baseline", "ARMv8-M Mainline", "ARMv8-M Mainline",
"ARMv8.1-M Mainline", "ARMv7-R", "ARMv7-R", "ARMv7-R", "ARMv7-R",
"ARMv8-R", "ARMv8-R", "ARMv7-A", "ARMv7-A", "ARMv7-A", "ARMv7-A",
"ARMv7-A", "ARMv7-A", "ARMv7-A", "ARMv8-A", "ARMv8-A", "ARMv8-A",
"ARMv8-A", "ARMv8-A", "ARMv8-A", "ARMv8-A", "ARMv8.2-A", "ARMv8.2-A",
"ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A",
"ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv9-A"
), Prozessor = c("ARM1", "ARM2", "ARM250", "ARM3", "ARM60", "ARM600",
"ARM610", "ARM700", "ARM710", "ARM710a", "ARM7TDMI(-S)", "ARM710T",
"ARM720T", "ARM740T", "ARM7EJ-S", "ARM810", "ARM9TDMI", "ARM920T",
"ARM922T", "ARM940T", "ARM946E-S", "ARM966E-S", "ARM968E-S",
"ARM926EJ-S", "ARM966HS", "ARM1020E", "ARM1022E", "ARM1026EJ-S",
"ARM1136J(F)-S", "ARM1156T2(F)-S", "ARM1176JZ(F)-S", "ARM11MPCore",
"SC000", "SC100", "SC300", "Cortex-M0", "Cortex-M0+", "Cortex-M1",
"Cortex-M3", "Cortex-M4", "Cortex-M7", "Cortex-M23", "Cortex-M33",
"Cortex-M35P", "Cortex-M55", "Cortex-R4", "Cortex-R5", "Cortex-R7",
"Cortex-R8", "Cortex-R52", "Cortex-R82", "Cortex-A5", "Cortex-A7",
"Cortex-A8", "Cortex-A9", "Cortex-A12", "Cortex-A15", "Cortex-A17",
"Cortex-A32", "Cortex-A34", "Cortex-A35", "Cortex-A53", "Cortex-A57",
"Cortex-A72", "Cortex-A73", "Cortex-A55", "Cortex-A65", "Cortex-A65AE",
"Cortex-A75", "Cortex-A76", "Cortex-A76AE", "Cortex-A77", "Cortex-A78",
"Cortex-A78AE", "Cortex-X1", "Cortex-A78C", "Cortex-A710")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -77L))
目前我正在用这个命令绘图:
ggplot(data = ARM,
aes(axis1 = Profil, axis2 = Familie, axis3 = Architektur, , axis4 = Prozessor)) +
scale_x_discrete(limits = c("Profil", "Familie", "Architektur", "Prozessor"), expand = c(.2, .05)) +
geom_alluvium(aes(fill = Architektur)) +
stat_stratum() +
ggfittext::geom_fit_text(stat = "stratum", min.size = 0, aes(label = after_stat(stratum))) +
theme_void()
这会导致非常“丑陋”的结果,有很多交叉点,因为 R 按字母顺序对层进行排序:
所以在我看来,最好的顺序是简单地保留输入数据的顺序。
如何归档此行为?我已经阅读了很多关于“因子”和“矿脉格式”的内容,但我不知道这一切是什么意思。
也许有人可以帮我解决这个问题。
亲切的问候
您可以通过将字符向量转换为因子并指定所需的级别来重新排序轴。第一个轴的演示:
ARM$Profil = factor(ARM$Profil, levels = unique(ARM$Profil))
我已经搜索并查看了类似(可能相同)问题的其他答案,但老实说,我没有得到相应的答案,因为我绝对不喜欢 R。
我基本上想做的是展示所有 Arm 架构和它们的实现(处理器)之间的关系,以及它们关于“配置文件”的家族分组。所以我有 4 个轴:配置文件、系列、架构和处理器。
我从维基百科 (https://en.wikipedia.org/wiki/List_of_ARM_microarchitectures) 中获取数据并将其输入 excel 以便能够将其导入 R-Studio(再次:我刚刚安装了 R 和 R-Studio 并且完全没有使用这种语言和工具的经验)。我保留了“顺序”,所以基本上我只是在 Excel 中复制了 table 以便能够在 R-Studio 中导入数据。
> head(ARM)
# A tibble: 6 × 4
Profil Familie Architektur Prozessor
<chr> <chr> <chr> <chr>
1 Classic ARM1 ARMv1 ARM1
2 Classic ARM2 ARMv2 ARM2
3 Classic ARM2 ARMv2a ARM250
4 Classic ARM3 ARMv2a ARM3
5 Classic ARM6 ARMv3 ARM60
6 Classic ARM6 ARMv3 ARM600
完整数据:
> dput(ARM)
structure(list(Profil = c("Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Classic", "Classic",
"Classic", "Classic", "Classic", "Classic", "Microcontroller",
"Classic", "Microcontroller", "Microcontroller", "Microcontroller",
"Microcontroller", "Microcontroller", "Microcontroller", "Microcontroller",
"Microcontroller", "Microcontroller", "Microcontroller", "Microcontroller",
"Realtime", "Realtime", "Realtime", "Realtime", "Realtime", "Realtime",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application", "Application", "Application", "Application", "Application",
"Application"), Familie = c("ARM1", "ARM2", "ARM2", "ARM3", "ARM6",
"ARM6", "ARM6", "ARM7", "ARM7", "ARM7", "ARM7T", "ARM7T", "ARM7T",
"ARM7T", "ARM7EJ", "ARM8", "ARM9T", "ARM9T", "ARM9T", "ARM9T",
"ARM9E", "ARM9E", "ARM9E", "ARM9E", "ARM9E", "ARM10E", "ARM10E",
"ARM10E", "ARM11", "ARM11", "ARM11", "ARM11", "SecurCore", "SecurCore",
"SecurCore", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex", "Cortex",
"Cortex", "Cortex"), Architektur = c("ARMv1", "ARMv2", "ARMv2a",
"ARMv2a", "ARMv3", "ARMv3", "ARMv3", "ARMv3", "ARMv3", "ARMv3",
"ARMv4T", "ARMv4T", "ARMv4T", "ARMv4T", "ARMv5TEJ", "ARMv4",
"ARMv4T", "ARMv4T", "ARMv4T", "ARMv4T", "ARMv5TE", "ARMv5TE",
"ARMv5TE", "ARMv5TEJ", "ARMv5TE", "ARMv5TE", "ARMv5TE", "ARMv5TEJ",
"ARMv6", "ARMv6T2", "ARMv6Z", "ARMv6K", "ARMv6-M", "ARMv4T",
"ARMv7-M", "ARMv6-M", "ARMv6-M", "ARMv6-M", "ARMv7-M", "ARMv7E-M",
"ARMv7E-M", "ARMv8-M Baseline", "ARMv8-M Mainline", "ARMv8-M Mainline",
"ARMv8.1-M Mainline", "ARMv7-R", "ARMv7-R", "ARMv7-R", "ARMv7-R",
"ARMv8-R", "ARMv8-R", "ARMv7-A", "ARMv7-A", "ARMv7-A", "ARMv7-A",
"ARMv7-A", "ARMv7-A", "ARMv7-A", "ARMv8-A", "ARMv8-A", "ARMv8-A",
"ARMv8-A", "ARMv8-A", "ARMv8-A", "ARMv8-A", "ARMv8.2-A", "ARMv8.2-A",
"ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A",
"ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv8.2-A", "ARMv9-A"
), Prozessor = c("ARM1", "ARM2", "ARM250", "ARM3", "ARM60", "ARM600",
"ARM610", "ARM700", "ARM710", "ARM710a", "ARM7TDMI(-S)", "ARM710T",
"ARM720T", "ARM740T", "ARM7EJ-S", "ARM810", "ARM9TDMI", "ARM920T",
"ARM922T", "ARM940T", "ARM946E-S", "ARM966E-S", "ARM968E-S",
"ARM926EJ-S", "ARM966HS", "ARM1020E", "ARM1022E", "ARM1026EJ-S",
"ARM1136J(F)-S", "ARM1156T2(F)-S", "ARM1176JZ(F)-S", "ARM11MPCore",
"SC000", "SC100", "SC300", "Cortex-M0", "Cortex-M0+", "Cortex-M1",
"Cortex-M3", "Cortex-M4", "Cortex-M7", "Cortex-M23", "Cortex-M33",
"Cortex-M35P", "Cortex-M55", "Cortex-R4", "Cortex-R5", "Cortex-R7",
"Cortex-R8", "Cortex-R52", "Cortex-R82", "Cortex-A5", "Cortex-A7",
"Cortex-A8", "Cortex-A9", "Cortex-A12", "Cortex-A15", "Cortex-A17",
"Cortex-A32", "Cortex-A34", "Cortex-A35", "Cortex-A53", "Cortex-A57",
"Cortex-A72", "Cortex-A73", "Cortex-A55", "Cortex-A65", "Cortex-A65AE",
"Cortex-A75", "Cortex-A76", "Cortex-A76AE", "Cortex-A77", "Cortex-A78",
"Cortex-A78AE", "Cortex-X1", "Cortex-A78C", "Cortex-A710")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -77L))
目前我正在用这个命令绘图:
ggplot(data = ARM,
aes(axis1 = Profil, axis2 = Familie, axis3 = Architektur, , axis4 = Prozessor)) +
scale_x_discrete(limits = c("Profil", "Familie", "Architektur", "Prozessor"), expand = c(.2, .05)) +
geom_alluvium(aes(fill = Architektur)) +
stat_stratum() +
ggfittext::geom_fit_text(stat = "stratum", min.size = 0, aes(label = after_stat(stratum))) +
theme_void()
这会导致非常“丑陋”的结果,有很多交叉点,因为 R 按字母顺序对层进行排序:
所以在我看来,最好的顺序是简单地保留输入数据的顺序。
如何归档此行为?我已经阅读了很多关于“因子”和“矿脉格式”的内容,但我不知道这一切是什么意思。
也许有人可以帮我解决这个问题。
亲切的问候
您可以通过将字符向量转换为因子并指定所需的级别来重新排序轴。第一个轴的演示:
ARM$Profil = factor(ARM$Profil, levels = unique(ARM$Profil))