How to plot a graph like this

I would like to create a graph like this one. I have an excel table with all the parameters, do you know some package that might help me? Thank you. 81984867_10216197823321550_6477080109961445376_n|496x500

1 Like

Hello,

The type of plot you are looking for is called an "Allivial plot".
Luckily for you, there is a package called ggalluvial that implements this in ggplot. You can find more info about the package here:

Looking at your image, I came up with some basic approximation to showcase the idea:

library(ggplot2)
library(ggalluvial)
library(purrr)

options(stringsAsFactors = F)

#Generate dummy data
myData = map_df(paste0("Person", 1:9), function(x){
  data.frame(Person = x, 
             Characteristic = paste0("Characteristic ",
                                     sample(1:5, sample(2:5, 1))))
})


#Create the alluvial plot
ggplot(data = myData,
       aes(axis1 = Person, axis2 = Characteristic, y = 1)) +
  scale_x_discrete(limits = c("Person", "Characteristic")) +
  geom_alluvium(aes(fill = Characteristic), show.legend = FALSE) +
  geom_stratum() + geom_text(stat = "stratum", infer.label = TRUE) +
  theme_void() + ggtitle("Alluvial plot") + 
  theme(plot.title = element_text(hjust = 0.5, size = 20))

The geom_alluvium creates the lines between the boxes, the geom_stratum the boxes themselves. Given this is ggplot, you have a wide array of parameters you can alter in order the further customize the plot to look even more like your original one. You probably won't be able to replicate it exactly, but you can get pretty close :slight_smile:

By the way, on my search for the correct graph and package, I came across this great website where you can browse through all types of graphs available in R:

Hope this helps,
PJ

7 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.