对于一项任务,我正在绘制冲积图以总结当选前的政客职业。
有一个CSV文件版本,其数据可在此处找到- [link]
您会从阶层中注意到,它们都是沿着底部拖动的,我想知道是否有这些方法可以优化自己的定位,或者至少让我定位。
我有一个CSV版本,其中“ Lodes”对每个轴都是唯一的。
下面的图片应该更清楚地突出我的意思...
我尝试了许多通过stat_stratum方法抛出参数的变体-https://rdrr.io/cran/ggalluvial/man/stat_stratum.html
但是他们要么打破了图表,要么以无法确定差异的方式对其进行了更改。
library(ggplot2)
library(ggalluvial)
library(readr)
library(ggthemes)
party <- c(
"Conservatives" = "dodgerblue4",
"Independent" = "black",
"Labour" = "red",
"Liberal Democrats" = "gold2",
"Plaid Cymru" = "darkgreen",
"UKIP" = "darkmagenta"
)
# Variable to store Party colors
thing <- read.csv("rejig.csv", header= TRUE, na = (""))
show(thing)
ds <- as.data.frame(thing)
ggplot(data = ds,
aes(axis1 = State, axis2 = One, axis3 = Two, axis4 = Three, axis5 = Four, axis6 = Five, axis7 = Six, axis8 = Seven, axis9 = Eight, axis10 = Nine, axis11 = Ten, axis12 = Eleven, axis13 = Twelve, axis14 = Thirteen, axis15 = Fourteen, axis16 = Senedd,
y = Freq)) + # Loading the nodes each axis is currently alone apart from School and "Post" reflecting start and end points
scale_x_discrete(limits = c(), expand= c(.1,0.5)) +
scale_fill_manual(
values = party,
limits = names(party)
) +
# loading the variable values and assigning colors
geom_alluvium(aes(fill = Party)) + # letting the fill occur
geom_stratum(na.rm = FALSE, alpha = .25) + geom_text(stat = "stratum", label.strata = TRUE) +
geom_flow(knot.pos = 1) +
theme(axis.title.y = element_blank(), # removing the "frequency"
axis.text.y = element_blank(), # values as they're utterly
axis.ticks.y = element_blank(), # meaningless in this
legend.position = "bottom",
legend.background = element_rect(fill = "white", colour = "black"),
panel.background = element_rect(fill = "moccasin", colour = "moccasin"),
plot.background = element_rect(fill = "moccasin"),
panel.grid = element_line(colour = "moccasin") # removing white gridelines
)