我正在使用ggalluvial软件包为我拥有的某些数据制作多个冲积图,但我想尝试订购这些冲积图,以便可以在多个图之间进行比较。
以下是一些示例数据:
set.seed(234)
Data1 <- data.frame(
ID = rep(1:10, each = 6),
Group = rep(1:2, each = 30),
Week = rep(1:6, times = 10),
Y = sample(c("High", "Low", "None"), 60, replace = TRUE)
)
Data2 <- data.frame(
ID = rep(1:10, each = 6),
Group = rep(1:2, each = 30),
Week = rep(1:6, times = 10),
Y = sample(c("High", "Low", "None"), 60, replace = TRUE)
)
以及制作两个图形的一些示例代码:
plot1 <- ggplot(Data1,
aes(x = Week,
stratum = Y,
alluvium = ID,
fill = Y,
label = Y))+
facet_grid(Group ~.)+
scale_fill_manual(values = c("red", "yellow", "green3"))+
geom_flow(stat = "alluvium", lode.guidance = "frontback", color = "darkgray")+
geom_stratum()
plot2 <- ggplot(Data2,
aes(x = Week,
stratum = Y,
alluvium = ID,
fill = Y,
label = Y))+
facet_grid(Group ~.)+
scale_fill_manual(values = c("red", "yellow", "green3"))+
geom_flow(stat = "alluvium", lode.guidance = "frontback", color = "darkgray")+
geom_stratum()
有没有办法知道哪个冲积物属于哪个人?或指定冲积的顺序,例如,第一组和第二张图中的第一组冲积是相同的?我意识到这可能会使图形看起来有些糟糕,但是对于我的实际数据,第一周的结果在各个方面都相当均匀,因此我认为这是可以的。预先感谢。
答案 0 :(得分:2)
这时对我而言最有意义的方法是,使用新的层将alluvium
变量(在这种情况下为ID
)传递给label
美学。冲积统计和文本几何。如果参数(例如lode.guidance
)被传递相同的值,则新层应在每个轴上以相同顺序堆叠Alluvia,并且文本标签将与Allovia与地层相交的“凸角”重合。
这是您关于附加层的示例。注意,它是在 层之后添加的;否则文本将被填充的矩形遮盖。
library(ggalluvial)
#> Loading required package: ggplot2
set.seed(234)
Data1 <- data.frame(
ID = rep(1:10, each = 6),
Group = rep(1:2, each = 30),
Week = rep(1:6, times = 10),
Y = sample(c("High", "Low", "None"), 60, replace = TRUE)
)
Data2 <- data.frame(
ID = rep(1:10, each = 6),
Group = rep(1:2, each = 30),
Week = rep(1:6, times = 10),
Y = sample(c("High", "Low", "None"), 60, replace = TRUE)
)
ggplot(Data1,
aes(x = Week,
stratum = Y,
alluvium = ID,
fill = Y,
label = Y))+
facet_grid(Group ~.)+
scale_fill_manual(values = c("red", "yellow", "green3"))+
geom_flow(stat = "alluvium", lode.guidance = "frontback", color = "darkgray")+
geom_stratum()+
geom_text(stat = "alluvium", aes(label = ID), lode.guidance = "frontback")
ggplot(Data2,
aes(x = Week,
stratum = Y,
alluvium = ID,
fill = Y,
label = Y))+
facet_grid(Group ~.)+
scale_fill_manual(values = c("red", "yellow", "green3"))+
geom_flow(stat = "alluvium", lode.guidance = "frontback", color = "darkgray")+
geom_stratum()+
geom_text(stat = "alluvium", aes(label = ID), lode.guidance = "frontback")
由reprex package(v0.3.0)于2019-11-22创建