# NOT RUN {
data("biofam3c")
## Building sequence objects
child_seq <- seqdef(biofam3c$children, start = 15)
marr_seq <- seqdef(biofam3c$married, start = 15)
left_seq <- seqdef(biofam3c$left, start = 15)
## Choosing colors
attr(child_seq, "cpal") <- c("#66C2A5", "#FC8D62")
attr(marr_seq, "cpal") <- c("#AB82FF", "#E6AB02", "#E7298A")
attr(left_seq, "cpal") <- c("#A6CEE3", "#E31A1C")
# Defining the plot for state distribution plots of observations
ssp1 <- ssp(list("Parenthood" = child_seq, "Marriage" = marr_seq,
"Residence" = left_seq))
# Plotting ssp1
plot(ssp1)
# }
# NOT RUN {
# Defining the plot for sequence index plots of observations
ssp2 <- ssp(
list(child_seq, marr_seq, left_seq), type = "I", plots = "obs",
# Sorting subjects according to the beginning of the 2nd channel (marr_seq)
sortv = "from.start", sort.channel = 2,
# Controlling the size, positions, and names for channel labels
ylab.pos = c(1, 2, 1), cex.lab = 1, ylab = c("Children", "Married", "Residence"),
# Plotting without legend
with.legend = FALSE)
plot(ssp2)
# Plotting hidden Markov models
# Loading data
data("hmm_biofam")
# Plotting observations and most probable hidden states paths
ssp3 <- ssp(
hmm_biofam, type = "I", plots = "both",
# Sorting according to multidimensional scaling of hidden states paths
sortv = "mds.hidden",
# Controlling title
title = "Biofam", cex.title = 1.5,
# Labels for x axis and tick marks
xtlab = 15:30, xlab = "Age")
plot(ssp3)
# Computing the most probable paths of hidden states
hid <- hidden_paths(hmm_biofam)
# Giving names for hidden states
library(TraMineR)
alphabet(hid) <- paste("Hidden state", 1:5)
# Plotting observations and hidden state paths
ssp4 <- ssp(
hmm_biofam, type = "I", plots = "hidden.paths",
# Sequence object of most probable paths
hidden.paths = hid,
# Sorting according to the end of hidden state paths
sortv = "from.end", sort.channel = 0,
# Contolling legend position, type, and proportion
with.legend = "bottom.combined", legend.prop = 0.15,
# Plotting without title and y label
title = FALSE, ylab = FALSE)
plot(ssp4)
# }
Run the code above in your browser using DataLab