Modify the x axis labels of the library (ggseqplot)

73 Views Asked by At

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!

1

There are 1 best solutions below

2
On

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