I have a transition matrix as following:
1. A A B
2. B C A
3. A C C
where each column represents periods,each row represents an agent and each letter represents a state. I would like a create a plot such as Sankey Diagram which shows transitions from states to states in each period.
Agents' identities are not important.
So I would like to have a plot like this:
.
It seems that I can use networkD3 or googleVis packages. However since the position of each node is endogenously determined by the packages, I have no clue how to put the time aspect on X axis.
Any help or alternative visualization suggestions will be highly appreciated, Thanks a lot in advance,
You can reproduce the sample data by:
transitiondata <- data.frame("t1"=c("A","B","A"),
"t2"=c("A","C","C"),
"t3"=c("B","A","C"))
Self-answering from the future:
ggalluvial
package, which is perfect for this task, was developed during that time. In order to use it, we need to provide tidy data.Let's load the libraries we need:
Then need to create identifiers for the data before we convert it to tidy format. So the new data is like this:
Convert to tidy format
Here is how our data looks like:
And
ggplot2
andggalluvial
does the trick:And our transition (Sankey) plot is ready: