如何在R中使用seqplot配置x轴?

时间:2014-08-04 15:42:52

标签: r traminer

跟进另一个question concerning the y-axis of sequence plots,我正在寻找一种方法来使用R-package TraMineR来操纵序列图的x轴。

问题在于TraMineR提供了一种简单的方法来调整指定xtstep=的x轴。然而,这不能完全控制x轴,因为不可能指定刻度的数量,刻度标签和刻度的结束/极限彼此独立。在某些情况下,这可能是一个很好的功能,因为您可以看到使用此示例代码或授予下面的两个图像:

library(TraMineR) 
data(mvad)
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school",
                   "training")
mvad.labels <- c("Employment", "Further Education", "Higher Education",
                 "Joblessness", "School", "Training")
mvad.scodes <- c("EM", "FE", "HE", "JL", "SC", "TR")

## Define sequence objects
mvad.seq <- seqdef(mvad[, 17:86], alphabet = mvad.alphabet,
                   states = mvad.scodes, labels = mvad.labels, weights = mvad$weight)

## Plots
seqIplot(mvad.seq, border=NA, xtstep=1, sortv="from.start") # Many ticks, some tick labels, x-scale shows last month as tick 
seqIplot(mvad.seq, border=NA, xtstep=12, sortv="from.start") # Few ticks, few tick labels, x-scale ends before last 8 months

Sequence plot using xtstep=1 使用xtstep = 1

的序列索引图

Sequence plot using xtstep=12 使用xtstep = 12

的序列索引图

1 个答案:

答案 0 :(得分:2)

您可以使用axes = FALSE禁用x轴,然后生成自己的x轴。为此,您还必须禁用自动图例。这是一个例子:

seqIplot(mvad.seq, border=NA, sortv="from.start", axes = F, withlegend=F) 
axis(1, at=c(1,70)-.5, labels = c("Sep. 93","Jun. 99"))