I'm trying to use package Gmisc
and make a three column transition plot in R, the data is like this head(dat,10)
:
?.no X1 X2 X3
1 2 S
2 6 E E E
3 11 E
4 12 E
5 14 N
6 16 N
7 17 E S
8 17 S S
9 18 E
10 18 N
It has empty cells in both column 2 and 3. The result of dput(data)
is:
structure(list(?.no = c(2L, 6L, 11L, 12L, 14L, 16L, 17L, 17L,
18L, 18L, 19L, 19L, 21L, 21L, 22L, 25L, 28L, 29L, 58L, 62L, 63L,
64L, 165L, 166L, 167L, 168L, 171L, 173L, 179L, 181L, 182L, 183L,
184L, 185L, 188L, 196L, 197L, 198L, 199L, 211L, 213L, 215L, 218L,
219L, 221L, 224L, 225L, 226L, 232L, 268L), X1 = c("S", "E", "E",
"E", "N", "N", "E", "S", "E", "N", "E", "E", "E", "S", "N", "E",
"E", "S", "E", "N", "E", "E", "N", "N", "N", "N", "S", "E", "E",
"E", "E", "N", "E", "S", "E", "E", "N", "E", "S", "N", "E", "E",
"E", "E", "N", "N", "E", "E", "E", "E"), X2 = c("", "E", "",
"", "", "", "S", "S", "", "", "E", "", "", "", "E", "", "", "",
"", "E", "E", "", "E", "", "", "E", "", "", "", "", "", "E",
"N", "", "", "", "", "", "", "E", "", "", "E", "", "", "S", "",
"", "", ""), X3 = c("", "E", "", "", "", "", "", "", "", "",
"", "", "", "", "E", "", "", "", "", "E", "E", "", "E", "", "",
"E", "", "", "", "", "", "", "N", "", "", "", "", "", "", "E",
"", "", "E", "", "", "N", "", "", "", "")), .Names = c("?.no",
"X1", "X2", "X3"), class = "data.frame", row.names = c(NA, -50L
))
The code for the transition plot :
library(Gmisc)
library(magrittr)
clr<-c("darkblue","orange","darkgreen")
clr1<-c("grey","darkblue","orange","darkgreen")
transitions <- table(dat$X1,dat$X2)%>%
getRefClass("Transition")$new(label=c("1st", "2nd"))
transitions$fill_clr[[1]] = clr;
transitions$fill_clr[[2]] = clr1;
table(dat$X2,dat$X3) %>% transitions$addTransitions(label = '3rd')
transitions$render()
the output:
And then I have two problems:
1 some narrow arrows cannot be visualized. my first transition matrix table(dat$X1,dat$X2)
is like this:
E N S
E 23 4 1 1
N 7 6 0 1
S 6 0 0 1
But the arrows from N to S and S to S are missing. The third column as well
table(dat$X2,dat$X2)
E N
36 0 0
E 2 8 0
N 0 0 1
S 2 0 1
2 So because there are so much empty value to distract attention (shown in grey in figure), I would like to remove the empty value which means the record don't have any category at next stage/column. I'm interested on the records which have value for all three stages but still want to keep the origin data set to show the proportion. The question is similar to Transition State Diagram R But I have empty values at both 2 and 3 column.
Basically, what I did is to remove empty values from the second and third column, by using the same ways as mentioned in precious link, manually set the transitions$transitions
to 0. But the figure turns out to be wrong
transition plot after remove , compare to the origin figure, the proportion of blue and orange changed, it apparently because I changed the transitions$transitions
.
Is there any other way to remove the empty values without changing transitions$transitions
? Simply just remove some certain boxes and arrow linked to those boxes?
Of course I understand, the empty value could be treat as a new category and I could simply keep as it is, but those empty value is meaningless for my study question thus I wish to get ride of them.
Hope I explain it well and many thanks