我正在使用R包TraMineR
。我想使用命令seqpcplot
绘制频繁的事件序列。我之前编写了alphabet
中的状态,以便按字母顺序对它们进行编码,以便在使用seqdef
命令计算序列时不指定labels
和states
选项我获得了以下输出:
[>] state coding:
[alphabet] [label] [long label]
1 a.sin a.sin a.sin
2 b.co0 b.co0 b.co0
3 c.co1 c.co1 c.co1
4 d.co2+ d.co2+ d.co2+
5 e.ma0 e.ma0 e.ma0
6 f.ma1 f.ma1 f.ma1
7 g.ma2+ g.ma2+ g.ma2+
8 h.sin0 h.sin0 h.sin0
9 i.lp1 i.lp1 i.lp1
10 l.lp2+ l.lp2+ l.lp2+
11 m.lp1_18 m.lp1_18 m.lp1_18
12 n.lp2_18 n.lp2_18 n.lp2_18
然后我使用seqecreate
在事件序列对象中转换状态序列对象。当通过seqpcplot
绘制事件序列时,我获得了一个非常好的图表,其中状态按照alphabet
在y轴上按字母顺序排序。
但是,我想在图表中使用更长的标签,以便我在labels
命令中指定states
和seqdef
选项为
lab<-c("single", "cohabNOchildren","cohab1child","cohab2+children","marrNOchildren","marr1child","marr2+children","singleNOchildren","loneMother1child","loneMother2+children","loneMother1child_over18","loneMother2+children_over18")
获得:
[>] state coding:
[alphabet] [label] [long label]
1 a.sin single single
2 b.co0 cohabNOchildren cohabNOchildren
3 c.co1 cohab1child cohab1child
4 d.co2+ cohab2+children cohab2+children
5 e.ma0 marrNOchildren marrNOchildren
6 f.ma1 marr1child marr1child
7 g.ma2+ marr2+children marr2+children
8 h.sin0 singleNOchildren singleNOchildren
9 i.lp1 loneMother1child loneMother1child
10 l.lp2+ loneMother2+children loneMother2+children
11 m.lp1_18 loneMother1child_over18 loneMother1child_over18
12 n.lp2_18 loneMother2+children_over18 loneMother2+children_over18
和以前一样,我然后使用seqpcplot
:
seqpcplot(example.seqe,
filter = list(type = "function",
value = "cumfreq",
level = 0.8),
order.align = "last",
ltype = "non-embeddable",
cex = 1.5, lwd = .9,
lcourse = "downwards")
这次y轴上的状态是状态按字母顺序排序,但遵循labels
和states
标签而不是alphabet
给出的顺序,正如我所希望的那样。
当指定了alphabet
和seqpcplot
选项并且可能遵循不同的字母顺序时,是否可以在labels
时使用states
保留字母顺序来自alphabet
?
感谢。
答案 0 :(得分:2)
我同意上述解决方案。作为补充,这里有许多可能的解决方案:
在seqecreate
中使用alphabet
和seqpcplot
参数:
dat <- data.frame(id = factor(1, 1, 1),
timestamp = c(0, 20, 22),
event = factor(c("A", "B", "C")))
dat.seqe <- seqecreate(dat)
seqpcplot(dat.seqe, alphabet = c("C", "A", "B"))
仅使用seqecreate
dat <- data.frame(id = factor(1, 1, 1),
timestamp = c(0, 20, 22),
event = factor(c("A", "B", "C"),levels = c("C", "A", "B")))
dat.seqe <- seqecreate(dat)
seqpcplot(dat.seqe)
使用seqdef
(此处原始类别与要在y轴上显示的标签不同)
dat <- data.frame(id = factor(1),
ev.0 = factor("AA", levels = c("CC", "AA", "BB")),
ev.20 = factor("BB", levels = c("CC", "AA", "BB")),
ev.22 = factor("CC", levels = c("CC", "AA", "BB")))
dat.seq <- seqdef(dat, var = 2:4, alphabet = c("CC", "AA", "BB"),
states = c("C", "A", "B"))
seqpcplot(dat.seq)
最后一个解决方案可能是您正在寻找的解决方案。希望它有所帮助。
答案 1 :(得分:1)
alphabet
函数的seqpcplot
参数用于控制该顺序。像
seqpcplot(example.seqe,
alphabet = lab,
filter = list(type = "function",
value = "cumfreq",
level = 0.8),
order.align = "last",
ltype = "non-embeddable",
cex = 1.5, lwd = .9,
lcourse = "downwards")
应该给你预期的情节。