4
$\begingroup$

I am trying to visualise a transition from one state (work in origin country) and another (work in destination country). I think transition plot is perfect but I can't get how does it work?

My data frame is called (Cimad) and my variables are EMPLOIPRE (origin) and EMPLOIFR (destination). Both are factors, the first count 20 levels, the second 15 levels (is it a problem, do I have to make them all match?) and I have 400 observations.

I hope you'll be able to help me because I am completely lost ! Thank you in advance Caroline.

$\endgroup$
3
  • $\begingroup$ What do you mean by "transition plot" - bipartite graph, sankey diagram, ...? Can you post the data set or example data that mimics it? (See my answer for one way to create example data.) $\endgroup$
    – lukeA
    Oct 28, 2016 at 23:45
  • $\begingroup$ Thank you very much for your answers ! Actually I am looking for something closer to the image below ![enter image description here](i.stack.imgur.com/jAazR.png) $\endgroup$
    – caroline
    Oct 31, 2016 at 13:17
  • $\begingroup$ Sorry everyone, Since I was new I did not registered at first and asked my question, but now I am registered and it's like it's not me who asked... well if you prefer I will build a new subject to follow this one? Otherwise thank you Sobach for your answer I will have a look at it. However, it looks like I have to process the data myself because it doesn't look automatically processed which is fine but it's better to know this fact before ! Abhishek I appreciate your post, however I already had a look at these posts but never understood how it worked ;) it's fine I'll probably get it one day ! $\endgroup$
    – Caroline
    Oct 31, 2016 at 16:31

3 Answers 3

2
$\begingroup$

The problem with Sankey diagram in your case is that you will duplicate all the nodes (on the left, and on the right), that is messy.

Networks are better, but nodes are not well structured.

I suggest to try chord diagrams for such data.

chord example

One of the greatest examples of chord diagram was build with d3.js, and based on migration flows dataset. Here is an R wrapper for d3.js chords. Or you can try to reproduce this manual.

$\endgroup$
1
$\begingroup$

Fwiw, here's an example

# create example data
set.seed(1)
Cimad <- data.frame(
  EMPLOIPRE = as.factor(sample(letters[1:15], 400, T)),
  EMPLOIFR = as.factor(sample(letters[1:20], 400, T))
)

# create adjacency/transition matrix
labs <- unique(unlist(Cimad))
m <- table(factor(Cimad[,1], lev=labs), factor(Cimad[,2], lev=labs))
m <- m / rowSums(m)

# plot it
library(igraph)
g <- graph_from_adjacency_matrix(m, weighted = "prob")
E(g)$prob <- ifelse(is.nan(E(g)$prob), NA, E(g)$prob)
plot(g, edge.label = round(E(g)$prob, 2), edge.arrow.size = .25, edge.label.cex = .5)

enter image description here

Or, if you want to export it into a PDF (e.g. for zoom):

pdf(tf <- tempfile(fileext = ".pdf"), width = 15, height = 15)
plot(g, edge.label = round(E(g)$prob, 2), edge.arrow.size = .25, edge.label.cex = .5)
dev.off()
shell.exec(tf)
$\endgroup$
2
  • $\begingroup$ Luke I followed for the moment your advice giving me this. How do you recommend to read it, is there any manual on the internet? Because everything is in letters while in my file they are categories ! Thank you again for your help and your work on this R community ;) ![enter image description here](i.stack.imgur.com/1epnx.png) $\endgroup$
    – Caroline
    Oct 31, 2016 at 13:39
  • $\begingroup$ The edges show transition probabilities - see e.g. probabilitycourse.com/chapter11/… $\endgroup$
    – lukeA
    Nov 2, 2016 at 14:30
0
$\begingroup$

if you're looking for something like this--

enter image description here

Then these resources can be very useful for you. Have a look-

Apart from these, there is an interesting post on stack overflow as well. I hope this will help. Cheers!

$\endgroup$
1
  • $\begingroup$ Unfortunately this package is not available for R 3.3.1 $\endgroup$ Oct 27, 2017 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.