2

enter image description hereA common problem1 2 in the publication of a sequence analysis or generally of graphs with many categorical states is that they are not easily transferable to b/w paper publications. There are some tools, like Colorbrewer, which can help to make a well informed decision on grey scale colors. Nonetheless, the results are unsatisfactory if the color palette exceeds 5 or more shades of greys. Thus, it would be really helpful to add pattern fills to certain graph areas in these cases (although this is not recommended by the famous Edward Tufte).

Would it be possible to use the pattern fill abilities of R base graphics or an extension of the base graphics to add fill patterns to TraMineRgraphs?

Here is small example of a sequence index plot:

library(TraMineR)

library(RColorBrewer)

## Load example dataset with 8 sequence states 
data(biofam)

## Define sequence objects 
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
                "Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab)

## Example plot in colors
seqiplot(biofam.seq, cex.legend=.7)

## Example plot in greys for b/w publication
seqiplot(biofam.seq, cex.legend=.7, cpal=brewer.pal(8, "Greys"))

Sequence index plot in color Sequence index plot in unadjusted greys for b/w publication

Community
  • 1
  • 1
  • 1
    `TraMineR` use base graphic not `ggplot2` nor `grid` (except some peculiar functions). Most of the graphics relies on `barplot`. This is a very frequent question and I would be really interested in any answer. – Matthias Studer Feb 24 '15 at 16:26
  • 1
    As explained my Matthias at http://lists.r-forge.r-project.org/pipermail/traminer-users/2010-June/000017.html , you can try to play with the `density`and `angle` arguments that will be passed to barplot when `seqplot` calls this function, e.g. `seqiplot(mvad.seq, cpal=brewer.pal(6, "Greys"), density=11:16, angle=1:6*5, border=NA)` . However, the solution is all but convincing. I would also be interested in a professional looking solution. – Gilbert Feb 24 '15 at 19:45
  • Many thanks for pointing out, that TraMineR uses the base graphs. Using the small hack from this [SO answer](http://stackoverflow.com/questions/23913276/texture-in-barplot-for-7-bars-in-r), the density/angle options could at least be used to get ~6 differentiable grids, combined with 5 shades of grey that would be already something. – non-numeric_argument Feb 25 '15 at 14:51

1 Answers1

1

Following the comments, I came up with this "solution" whose graphics are still improvable. Unfortunately, I was not able to overwrite the legends as well, so that they still need some work. I would be happy if someone had an idea!?

## Define smaller black/grey palette, delete almost white tones
greys <- c("black", "black", "black", "black", brewer.pal(5, "Greys")[2:5])

## Example plot using density and overwriting angle options
par(mar=c(1,2,1,1))
layout(matrix(c(1,2), 2, 1, byrow = TRUE), heights=c(2,1))
seqiplot(biofam.seq, withlegend=FALSE,
         cpal=greys,
         density=c(20, 20, 20, 20, -1, -1, -1, -1), 
         angle=c(45, 90, 45, 0, 0, 0, 0, 0))
seqiplot(biofam.seq, withlegend=FALSE,
         cpal=greys,
         density=c(20, 20, 20, 20, -1, -1, -1, -1), 
         angle=c(45, 90, 135, 0, 0, 0, 0, 0),
         add=TRUE)
         # Different angle for third state creates grid instead of patterns
seqlegend(biofam.seq, pos="center", ncol=3, fontsize=.7,
          cpal=greys,
          density=c(20, 20, 20, 20, -1, -1, -1, -1), 
          angle=c(45, 90, 45, 0, 0, 0, 0, 0))
seqlegend(biofam.seq, pos="center", ncol=3, fontsize=.7,
          cpal=greys,
          density=c(20, 20, 20, 20, -1, -1, -1, -1), 
          angle=c(45, 90, 135, 0, 0, 0, 0, 0))
          # Draws an additional legend instead of overwriting the first

enter image description here

  • The `add=TRUE` option doesn't work for me, when doing a grouped graph. The second plot just comes as a grey area on one of the group subgraphs from the first plot. Perhaps the group option creates its own layout? How to counter that, I wonder. – Maxim.K Mar 17 '15 at 10:22
  • 1
    If you are using the `group=` option of `seqplot`, then, yes, it calls `layout` on its own. In this case, you cannot use `group=` and you need to make graphs per group by subsetting the dataset for each group. Have a look at this [SO comment](http://stackoverflow.com/questions/18187308/how-to-configure-y-axis-using-seqiplot-in-r#comment26729275_18224257). – non-numeric_argument Mar 23 '15 at 15:30
  • Thank you for this clarification. I am curious though, if this method works for a single-group graph, and seqplot() interferes with the layout, preventing this method to be used for multiple groups; wouldn't it then be possible to implement this method *inside* seqplot(), @MatthiasStuder? One can be certain that publishing the results of sequence analysis in b/w print journals is a very common tasks. There should be tools geared towards that goal, and this method seems like an easy way out. – Maxim.K Mar 24 '15 at 15:37