我的数据看起来像这样:
输出dput(sequence_data)
;
structure(list(Obs = 1:13, Seq.1 = structure(c(1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("a", "b", "c"
), class = "factor"), Seq.2 = structure(c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("c", "d"), class = "factor"),
Seq.3 = structure(c(1L, 1L, 1L, 2L, 1L, 1L, 3L, 3L, 3L, 3L,
3L, 3L, 3L), .Label = c("", "d", "e"), class = "factor"),
Seq.4 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 2L), .Label = c("", "f"), class = "factor")), .Names = c("Obs",
"Seq.1", "Seq.2", "Seq.3", "Seq.4"), class = "data.frame", row.names = c(NA,
-13L))
我正在尝试获取过渡状态图。这是代码:
transitions <- table(sequence_data$Seq.1,sequence_data$Seq.2) %>%
getRefClass("Transition")$new(label=c("1st Iteration", "2nd Iteration"))
transitions$box_width = 0.25;
transitions$box_label_cex = 0.7;
transitions$arrow_type = "simple";
transitions$arrow_rez = 300;
table(sequence_data$Seq.2,sequence_data$Seq.3) %>% transitions$addTransitions(label = '3rd Iteration')
transitions$render()
这是输出:
是否可以从图中删除空值,使其看起来更干净?我尝试删除,但是表语句需要这些值的长度相同。
我正在为图表使用GMISC软件包(
library(Gmisc)
)。谢谢
最佳答案
这可能有点hacky,但可以带您到那里。基本上,您可以手动将转换(transitions$transitions
)设置为0
。
transitions$transitions[[2]][1,1] = 0
transitions$transitions[[2]][2,1] = 0
transitions$render()
也许此循环可以自动将所有值更改为
0
(尽管我尚未检查大数据)for (level_n in 1:length(transitions$transitions)){
x = transitions$transitions[[level_n]]
for (cols in 1:ncol(transitions$transitions[[level_n]])){
if (dimnames(x)[[2]][cols] == ""){
transitions$transitions[[level_n]][,cols] = 0
}
}
}
关于r - 过渡状态图R,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41769650/