I am trying to calculate how many (sum total) transitions happened between multiple states. I saw that this could be easily achieved by using html tables in Gmisc (open to other suggestions).

I have 2 columns called 'before' and 'after' and there are technically 23 states in total, with alphabetic character labels.

Code I used:

b4 <- b4 %>%

mutate_at(vars(1:1),

~as.numeric(recode(.,

"a"=1,

"b"=2,

"c"=3,

"d"=4,

"e"=5,

"f"=6,

"g"=7

"h"=8)))

b4 <- data.matrix(b4)

af <- af %>%

mutate_at(vars(1:1),

~as.numeric(recode(.,

"a"=1,

"b"=2,

"c"=3,

"d"=4,

"e"=5,

"f"=6,

"g"=7

"h"=8)))

af <- data.matrix(af)

b4 <- factor(b4)

af <- factor(af)

transition.mtrx <- table(b4,af)

htmlTable(transition.mtrx, title ' "transitions', ctable = TRUE)

The issue is that this only seems to accept numerical inputs (so I changed it as such). However; to get the labels to be correct on the final plot I need to manually type out

labels = c("a","b"......) when I know which transitions took place.

I was wondering if anyone knew how to say "look at the transition labels and change them back to the alphabetical original ones" or if there is a better way of doing this.