Давайте попробуем:
# load some packages!
library(alluvial)
library(ggalluvial)
require(ggplot2)
library(reshape)
# put the seed, to have consistency in random sample
set.seed(1)
data <- data.frame(row.names = paste0("SP","",1:30),
id = paste0("SP","",1:30), # added the rowlabels as id
COL1 = rep(sample(LETTERS[1:3]),10),
COL2 = rep(sample(LETTERS[1:3]),10), # rename a column
COL3 =rep(sample(LETTERS[1:3]),10))
# put data in long format, for ggplot
mdata <- melt(data, id=c("id"))
# here the sankey, if it's like you want it
ggplot(mdata,aes(x = variable, stratum = value, alluvium = id, fill = value, label = value))+
geom_flow(stat = "alluvium", lode.guidance = "rightleft") +
geom_stratum() + geom_text(stat = "stratum")+
theme(legend.position = "none") +
ggtitle("test")
Вот результат.