3
$\begingroup$

I have a problem with the legend of a TraMineR graph.

I have computed the 4 different entropies for the 4 cohorts that I'm analyzing and I would like to plot them in the same graph using the seqplot.tentrop function. However, the default legend is too big and I would plot it separately reducing the dimensions, but I can't reproduce the colors of the legend in the new one I've created with the last command below.

    plot_colors <- c("blue", "red", "forestgreen", "purple")
    seqplot.tentrop(myseq, group = job$cohort, ylim = c(0, 1), 
      col=plot_colors, withlegend=FALSE)
    legend("bottomright", names(myseq), 
      c("1974-1978","1982-1986","1990-1994", "1998-2001"),
      cex=0.8, col=plot_colors)

Is it possible to change colors/dotted lines?

$\endgroup$
4
$\begingroup$

Just to make it clear, the seqplot.tentrop function is currently provided by the TraMineRextras package, not TraMineR.

Now regarding your problem. You are in trouble because you don't provide the line types to legend(). Function seqplot.tentrop assigns default line tyes. You can override them to be sure to use the same ones for the plot and the legend. Here is how your code should look out:

plot_colors <- c("blue", "red", "forestgreen", "purple") 
plot_lty <-  c("solid","dashed","dotted","solid") 
seqplot.tentrop(myseq, group = job$cohort, ylim = c(0, 1), 
       lty=plot_lty, col=plot_colors, withlegend=FALSE)

legend("bottomright",
       legend=c("1974-1978","1982-1986","1990-1994","1998-2001"),           
       cex=0.8, lty=plot_lty, col=plot_colors)

Furthermore, it may be useful to control the line thickness with the lwd argument. For example, lwd=2 would double the line thickness.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.