在 TraMineR 中使用 seqpcplot 时保持 y 轴上的标签顺序
Keeping the label order on the y-axis when using seqpcplot in TraMineR
我正在使用 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 轴上按字母顺序排列
但是,我想在图表中使用更长的标签,所以我在 seqdef
命令中将 labels
和 states
选项指定为
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
,因为我希望。
当使用 seqpcplot
绘图时,当指定了 labels
和 states
选项时,有没有办法保持 alphabet
中给出的字母顺序,并且可能遵循与 alphabet
?
不同的字母顺序
谢谢。
seqpcplot
函数的 alphabet
参数用于控制该顺序。像
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")
应该给你预期的情节。
我同意上面的解决方案。作为补充,这里有一些可能的解决方案:
使用 seqecreate
和 seqpcplot
中的 alphabet
参数:
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)
最后一个解决方案可能就是您要找的那个。希望对你有帮助。
我正在使用 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
.
但是,我想在图表中使用更长的标签,所以我在 seqdef
命令中将 labels
和 states
选项指定为
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
,因为我希望。
当使用 seqpcplot
绘图时,当指定了 labels
和 states
选项时,有没有办法保持 alphabet
中给出的字母顺序,并且可能遵循与 alphabet
?
谢谢。
seqpcplot
函数的 alphabet
参数用于控制该顺序。像
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")
应该给你预期的情节。
我同意上面的解决方案。作为补充,这里有一些可能的解决方案:
使用 seqecreate
和 seqpcplot
中的 alphabet
参数:
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)
最后一个解决方案可能就是您要找的那个。希望对你有帮助。