我正在使用 ggplot 和 geom_alluvium。我很接近,但想问是否有任何方法可以在 Y 轴上的带/冲积层之间添加空间。
ggplot(data = mydata, aes(x = Year, y = Category, alluvium = OPP)) +
geom_alluvium(aes(fill = OPP, colour = OPP),
alpha = 0.9, decreasing = FALSE, width = 1/4) +
scale_x_continuous (breaks = seq(2015, 2016, 1),
labels = c("General", "Specific"))+
theme_minimal() +
labs(
y = "",
x = ""
) +
theme(
plot.margin = margin(2, 2, 2, 2, "cm"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
axis.text.x = element_text(size = 10, face = 'bold'),
axis.text.y = element_blank(),
axis.line.y = element_blank(),
axis.ticks.y = element_blank(),
axis.line.x = element_blank(),`enter code here`
axis.ticks.x = element_blank(),
legend. Position = "none") +
scale_fill_brewer(type = "qual", palette = "Set3") +
scale_color_brewer(type = "qual", palette = "Set3")
我认为冲积地块在 y 轴上堆叠,设计时脉络之间没有间隙;也许考虑使用桑基图代替?
例如
library(tidyverse)
library(ggsankey)
df <- read.table(text = "Player TG% Pts Team Opp Year Rd Category
John 56 42 A 1 2016 1 Grnd1
James 94 64 B 2 2016 1 Grnd1
Jerry 85 78 C 1 2016 1 Grnd1
Daniel 97 51 D 2 2016 1 Grnd1
John 89 61 A 1 2016 1 Grnd1
James 65 26 B 1 2016 1 Grnd1
Jerry 73 34 C 1 2016 1 Grnd2
Daniel 73 40 D 2 2016 1 Grnd2
John 89 26 A 2 2016 1 Grnd3
James 92 42 B 3 2016 1 Grnd1
Jerry 89 25 C 3 2016 1 Grnd2
Daniel 80 41 D 3 2016 1 Grnd2
John 73 82 A 3 2016 1 Grnd3
James 73 41 B 3 2017 1 Grnd3
Jerry 89 76 C 3 2017 1 Grnd1
Daniel 91 77 D 3 2017 1 Grnd2", header = TRUE)
df_long <- df %>%
make_long(Player, Opp, Category, Year)
df_long %>%
ggplot(aes(x = x,
next_x = next_x,
node = fct_rev(node),
next_node = fct_rev(next_node),
fill = factor(node),
label = node)) +
geom_sankey() +
geom_sankey_label() +
theme_sankey(base_size = 16) +
theme(legend.position = "none")
df_long %>%
ggplot(aes(x = x,
next_x = next_x,
node = fct_rev(node),
next_node = fct_rev(next_node),
fill = factor(node),
label = node)) +
geom_sankey(space = 10) +
geom_sankey_label(space = 10) +
theme_sankey(base_size = 16) +
theme(legend.position = "none")
创建于 2024 年 12 月 19 日,使用 reprex v2.1.0