1

I have a question regarding the seqrplot function in the R TraMineR package which plots sets of representative sequences. I have a big dataset on infringement proceedings with EU law (due to the length of the proceedings, I use the seqgranularity function) and use the following code.

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)

However, the plot does not seem to take into account the colour palette which is attributed to the sequence object. Instead it returns the representative sequences in black (see screenshot). I checked my par() settings and they seem to be fine since all the other plots are duly coloured. Or is there any way of restoring the default setting of par()? I also tried to run the code with smaller subsamples but it didn't change the result. Does anybody have an idea how to solve this issue?

Thank you very much in advance!

Gilbert
  • 3,570
  • 18
  • 28

1 Answers1

0

The issue probably arises because of the small boxes drawn around each observation. The solution is to use the border=NA argument. I illustrate using your data. However, with your federal group variable, one group has only one sequence while seqrplot requires at least two sequences by group. Therefore, I change the federal value for sequence 2.

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

and as you can see below, the colors show up as expected

enter image description here

Gilbert
  • 3,570
  • 18
  • 28
  • Thank you Gilbert for taking the time. I also managed to make it work without the border=NA argument. There was a mistake in my long code; apparently, one has to reload the grDevices package after loading te TraMineRextras package (which I have omitted in my original code). Thank you very much anyway! – S. Lutzenberger Feb 23 '18 at 17:25
  • That sounds curious. `grDevices` is a base package that usually is automatically loaded when R is started. For me everything works fine without issuing `library(grDevices)`, neither before nor after loading `TraMineRextras`. – Gilbert Feb 24 '18 at 09:03