0

大家好。我正在尝试使用 ggalluvial 显示结果。我在数据库中有一组数据显示几个人,我想在一个 ggalluvium 图中显示这些结果,第一个显示在第一个事件(groupe_pathogen1)的人员重新分区中,一个冲积层,然后是第二行在第二个事件 (groupe_pathogen2) 中显示人员的重新分区。

我无法显示此 ggalluvium,可能主要是因为我无法以适当的方式汇总我的数据,有人可以帮助了解我在哪里出错找到她的代码,在此先感谢 R

library(ggplot2)
library(ggalluvial)

setwd ("C:\\  \\  \\  \\  \\")

bob<-read.csv (file="donnes_graph_oi.csv", sep=";", header=F)

bob$id<-bob$V1
bob$V1<-NULL
bob$infection_1<-bob$V2
bob$V2<-NULL
bob$infection_2<-bob$V3
bob$V3<-NULL
bob$groupe_pathogene_1<-bob$V4
bob$V4<-NULL
bob$groupe_pathogene_2<-bob$V5
bob$V5<-NULL
bob$number<-1


 
bob$groupe_pathogene_1 <- as.character(bob$groupe_pathogene_1)
bob$groupe_pathogene_2 <- as.character(bob$groupe_pathogene_2)

## aggregation of the data 
aggregated_data_1 <- aggregate (number ~bob$groupe_pathogene_1 + bob$groupe_pathogene_2, bob, sum)

## creation of the plot
ggplot(as.data.frame(aggregated),       aes(y=number , axis1 =bob$groupe_pathogene_1, axis2 =bob$groupe_pathogene_2))+
  geom_alluvium(aes(fill =bob$groupe_pathogene_1), width = 1/12)+
  geom_stratum(width = 1/5, fill = "grey", color = "black")+
  geom_label(stat = "stratum", aes(label = after_stat(stratum)), size=6,)+
  scale_x_discrete(limits = c("First infection", "Second infection"), expand = c(.05, .05))+
  scale_fill_brewer(type = "qual", palette = "Set1")   ```
4

0 回答 0