trajectories ships with Nestimate: 138 student sequences
× 15 weeks, three states (Active, Average,
Disengaged) plus NA for missed weeks.
data(trajectories)
dim(trajectories)
#> [1] 138 15
head(trajectories[, 1:8])
#> 1 2 3 4 5 6
#> [1,] "Active" "Disengaged" "Disengaged" "Disengaged" "Active" "Active"
#> [2,] "Average" "Average" "Average" "Average" "Average" "Average"
#> [3,] "Average" "Active" "Active" "Active" "Active" "Active"
#> [4,] "Active" "Active" "Active" "Active" "Active" "Average"
#> [5,] "Active" "Active" "Active" "Average" "Active" "Average"
#> [6,] "Average" "Average" "Disengaged" "Average" "Disengaged" "Disengaged"
#> 7 8
#> [1,] "Active" "Active"
#> [2,] "Average" "Average"
#> [3,] "Active" "Active"
#> [4,] "Average" "Active"
#> [5,] "Active" "Active"
#> [6,] "Average" "Average"
sort(unique(as.vector(trajectories)), na.last = NA)
#> [1] "Active" "Average" "Disengaged"sequence_plot() is the single entry point for three
views of this data:
type |
What it shows | Uses dendrogram? | Facets? |
|---|---|---|---|
"heatmap" (default) |
dense carpet, rows sorted by a distance/dendrogram | yes | no |
"index" |
carpet without dendrogram, row-gap optional | no | yes |
"distribution" |
stacked area / bar of state proportions over time | no | yes |
Defaults: legend = "right",
frame = FALSE.
type = "heatmap" — clustered carpetAvailable sorts: lcs (default), frequency,
start, end, plus any
build_clusters() distance — hamming,
osa, lv, dl, qgram,
cosine, jaccard, jw.
kCut the dendrogram into k groups and overlay thin
horizontal lines at the cluster boundaries in the ordered rows. Tune
with k_color and k_line_width.
sequence_plot(trajectories, k = 5,
k_color = "black", k_line_width = 1.2,
main = "k = 5 — thin black")sequence_plot(trajectories,
legend = "bottom",
legend_title = "Engagement",
state_colors = c("#2a9d8f", "#e9c46a", "#e76f51"),
main = "Custom palette + bottom legend")tick thinningtype = "index" — gap-ready carpet with facetsNo dendrogram. Rows are sorted within each panel by
sort. Supports group (vector or auto from a
net_clustering) plus ncol / nrow
facet grids.
type = "distribution" — state proportions over
timeStacked area or bar chart of state frequencies per time column.
sequence_plot(trajectories, type = "distribution",
geom = "bar", scale = "count",
main = "distribution — bars, count scale")# Always explore first with the default:
sequence_plot(trajectories)
# Zoom in on cluster structure:
sequence_plot(trajectories, k = 3)
sequence_plot(trajectories, sort = "hamming", k = 4)
# Compare cluster compositions:
cl <- build_clusters(as.data.frame(trajectories), k = 3,
dissimilarity = "hamming", method = "ward.D2")
sequence_plot(cl, type = "index")
sequence_plot(cl, type = "distribution")
# Polish for a paper:
sequence_plot(trajectories, k = 3,
state_colors = c("#2a9d8f", "#e9c46a", "#e76f51"),
legend_title = "Engagement",
legend = "bottom",
cell_border = "grey70",
main = "Student engagement trajectories")