-1

I use the library (ggseqplot) to display a TraMineR graph in ggplot2 format.

library(ggseqplot)

plot <- ggseqdplot(mvad.seq)

I get this figure: enter image description here

I would like to modify the x axis labels which is continuous from y1 to y1440 (1 minute to 1440), and add y100, y200, y300, etc.

I can't transmit the data because it's quite heavy. Is there any way of changing the axis labels to suit us? This library is supposed to make things easier. Many thanks!

2
  • You can use ggplot functions like in other settings: so check scale_x_continuous or scale_x_date (depending on your data), check the breaks argument.
    – Maël
    Commented Nov 30, 2023 at 9:10
  • 1
    Also, please provide a reproducible data set, otherwise we can't give you proper solutions
    – Maël
    Commented Nov 30, 2023 at 9:11

1 Answer 1

3

The library indeed makes plotting easier, assuming some familiarity with ggplot2 functions (just like TraMineR's plot functions require some knowledge of base R's plot environment if you want to modify them). In this case, you need to know how to change the appearance of axis scales and that the position scale of the sequences - usually indicating time points - is conceived as a discrete scale. Hence, you need to use the function scale_x_discrete() to adjust the axis.

library(ggseqplot)

# Create a sequence object from the mvad data set
data(mvad)
mvad.seq <- seqdef(mvad[,17:86])


# Plot the sequence object: dplot with desired break points
ggseqdplot(mvad.seq) + 
  scale_x_discrete(breaks = c(1, seq(10,70,10)))
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.


# ... add own labels
ggseqdplot(mvad.seq) + 
  scale_x_discrete(breaks = c(1, seq(10,70,10)), 
                   labels = paste0("y", c(1, seq(10,70,10))))
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.

Created on 2023-11-30 with reprex v2.0.2

2
  • Many thanks! I displayed the entropy with ggseqdplot(mvad.seq, with.entropy = TRUE) but I would like to change the label, to translate it in french for example. Do you know how to do it?
    – JC_
    Commented Dec 1, 2023 at 8:49
  • You have to use scale_color_identity() (maybe there are other options ...): ggseqdplot(mvad.seq, with.entropy = T) + scale_color_identity(guide = "legend", name = NULL, labels = "entropie")
    – maraab
    Commented Dec 2, 2023 at 14:38

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