seqrplot 中不显示颜色

Colours don't show up in seqrplot

我对 R TraMineR 包中的 seqrplot 函数有疑问,该函数绘制了一组代表性序列。我有一个关于欧盟法律侵权诉讼的大数据集(由于诉讼的长度,我使用 seqgranularity 函数)并使用以下代码。

library(TraMineR)
library(TraMineRextras)
library(grDevices)

#example data
directives <-
   structure(list(id = c(891L, 6826L, 9451L, 8816L), country_short = structure(c(2L,1L, 1L, 1L), 
.Label = c("I", "P"), class = "factor"), year = c(1992L, 1981L, 1980L, 1980L), 
federal = c(0L, 1L, 1L, 1L), admin = c(5331L, 
1423L, 735L, 656L), pol = c(NA, NA, NA, 223L), adjud = c(NA, NA, NA, 330L), 
postlit = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_), 
ADM = structure(c(2L, 1L, 4L, 3L), .Label = c("(ADM,1423)", "(ADM,5331)", "(ADM,656)", 
"(ADM,735)"), class = "factor"), POL = structure(c(NA, NA, NA, 1L), .Label = "(POL,223)", 
class = "factor"), ADJ = structure(c(NA, NA, NA, 1L), .Label = "(ADJ,330)", 
class = "factor"), PLIT = structure(c(NA_integer_, NA_integer_, NA_integer_, NA_integer_), 
.Label = character(0), class = "factor")), .Names = c("id", "country_short", "year", "federal", 
"admin", "pol", "adjud", "postlit", "ADM", "POL", "ADJ", "PLIT"), row.names = c(NA, 4L), class = "data.frame")  

directives.seq<-seqdef(data=directives, var=9:12, xtstep=364, 
                       informat = "SPS", SPS.in=list(xfix="()",sdsep=","),
                       cpal=c("blue","gray","black","green"),
                       void="%", alphabet=c("ADM","POL","ADJ","PLIT"), 
                       labels=c("Administration phase","Political phase","Adjudication phase","Post-litigation phase"))
directives.seq.month<-seqgranularity(directives.seq, tspan=30, method="first")
directives.om<-seqdist(directives.seq.month, full.matrix=FALSE, method="OM", indel=1, sm="TRATE")
seqrplot(directives.seq.month, diss=directives.om, group=directives$federal, criterion="dist", nrep=3)

但是,情节似乎没有考虑到序列对象的调色板。相反,它 returns 黑色的代表性序列 (see screenshot)。我检查了我的 par() 设置,它们似乎很好,因为所有其他图都已适当着色。或者有什么方法可以恢复 par() 的默认设置?我还尝试 运行 具有较小子样本的代码,但它并没有改变结果。 有人知道如何解决这个问题吗?

非常感谢您!

出现此问题的原因可能是每个观察结果周围都画了小方框。解决方案是使用 border=NA 参数。我用你的数据来说明。但是,使用您的 federal 组变量,一个组只有一个序列,而 seqrplot 需要至少两个序列。因此,我更改了序列 2 的 federal 值。

directives$federal[2] <- 0
seqrplot(directives.seq.month, diss=directives.om, 
    group=directives$federal, criterion="dist", 
    nrep=2, border=NA)

正如您在下面看到的那样,颜色显示符合预期