# Use example data from TraMineR: actcal data set
data(actcal)
# We use only a sample of 300 cases
set.seed(1)
actcal <- actcal[sample(nrow(actcal), 300), ]
actcal.lab <- c("> 37 hours", "19-36 hours", "1-18 hours", "no work")
actcal.seq <- seqdef(actcal, 13:24, labels = actcal.lab)
# state distribution plots; grouped by sex
# with TraMineR::seqplot
seqdplot(actcal.seq, group = actcal$sex)
# with ggseqplot
ggseqdplot(actcal.seq, group = actcal$sex)
# with ggseqplot applying a few additional arguments, e.g. entropy line
ggseqdplot(actcal.seq, group = actcal$sex,
no.n = TRUE, with.entropy = TRUE, border = TRUE)
# break down the stacked plot to ease comparisons of distributions
ggseqdplot(actcal.seq, group = actcal$sex, dissect = "row")
# make use of ggplot functions for modifying the plot
ggseqdplot(actcal.seq) +
scale_x_discrete(labels = month.abb) +
labs(title = "State distribution plot", x = "Month") +
guides(fill = guide_legend(title = "Alphabet")) +
theme_classic() +
theme(plot.title = element_text(size = 30,
margin = margin(0, 0, 20, 0)),
plot.title.position = "plot")
Run the code above in your browser using DataLab