在 axis1 中具有一个值的 ggalluvial

问题描述 投票:0回答:1

我应该用以下数据框制作一个ggalluvial:

df <- data.frame(departure = c("Paris"), arrival = c("Nantes","Caen","Nice"), value = c(0.5625, 0.312, 0.125))

当我这样做时,因为我在轴 1 中只有一个元素,所以它并没有真正产生“冲积效应”。我得到以下结果:

df %>% 
  group_by(departure) %>% 
  ggplot(aes(y = value*100, axis1 = departure, axis2 = arrival)) +
  geom_alluvium(aes(fill = arrival), width = 1/12) +
  geom_stratum(width = 1/12, fill = "white", color = "grey") +
  geom_label(stat = "stratum", aes(label = after_stat(stratum))) +
  scale_x_discrete(limits = c("departure", "arrival"), expand = c(.05, .05)) +
  scale_fill_brewer(type = "qual", palette = "Set1") +
  theme(legend.position = "none")

我试图通过添加虚构的行来作弊,以获得预期的冲积效果。

df <- rbind(df, c("-", "Nantes", 0.5625))
df <- rbind(df, c("-", "Caen", 0.262))
df$value <- as.numeric(df$value)

是否可以用一个轴1制作一个美观的冲积图? 预先感谢您。

r ggplot2 charts sankey-diagram ggalluvial
1个回答
0
投票

您的数据结构不太适合冲积图。如果这是根据数据创建冲积图的练习,那么您就成功了;这就是给定数据的冲积图应该是什么样子。如果您想要更符合冲积图外观的东西,您可以尝试制作冲积图: library(tidygraph) library(ggraph) as_tbl_graph(df) %>% ggraph() + geom_edge_diagonal(aes(width = value, color = factor(to)), alpha = 0.3) + geom_node_tile(width = 1, height = 0.1, fill = "white") + geom_node_text(aes(label = name), angle = 90) + scale_edge_width_continuous(range = c(0, 120), limits = c(0, 1)) + scale_y_reverse() + coord_flip() + theme(legend.position = "none")

© www.soinside.com 2019 - 2024. All rights reserved.