我尝试使用包Gmisc
并在R中制作三列转换图,数据类似于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
第2列和第3列都有空单元格。dput(data)
的结果是:
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
))
转换图的代码:
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()
输出:
然后我有两个问题:
1一些窄箭头无法显示。我的第一个转换矩阵table(dat$X1,dat$X2)
是这样的:
E N S
E 23 4 1 1
N 7 6 0 1
S 6 0 0 1
但缺少从N到S和S到S的箭头。第三栏也是如此
table(dat$X2,dat$X2)
E N
36 0 0
E 2 8 0
N 0 0 1
S 2 0 1
2因为有很多空值可以分散注意力(图中灰色显示),我想删除空值,这意味着记录在下一阶段/列没有任何类别。我对所有三个阶段都有价值但仍希望保留原始数据集以显示比例的记录感兴趣。问题类似于Transition State Diagram R但我在2和3列都有空值。
基本上,我所做的是从第二和第三列中删除空值,使用与珍贵链接中提到的相同方式,手动将transitions$transitions
设置为0.但是数字结果是错误的
transition plot after remove ,与原始数字相比,蓝色和橙色的比例发生了变化,显然是因为我更改了transitions$transitions
。
有没有其他方法可以在不更改transitions$transitions
的情况下删除空值?只需删除链接到那些盒子的某些盒子和箭头?
当然我理解,空值可以被视为一个新类别,我可以简单地保持原样,但是这些空值对于我的研究问题毫无意义,因此我希望能够驾驭它们。
希望我解释得很好,非常感谢
答案 0 :(得分:0)
这就是min_lwd
的用途:
transitions$min_lwd <- 0.01
我不确定我会在你问题的第二部分跟踪你。图的大小与输入成正比。