plot_modal: Generates a plot of the modal states

Description Usage Arguments Value Examples

View source: R/plotting.R

Description

Generates a plot of the modal states

Usage

1
2
3
4
5
6
plot_modal(
  seq_def_tidy,
  color_mapping = NULL,
  cluster_labels = NULL,
  n_col_facets = 1
)

Arguments

seq_def_tidy

a tidy tibble generated from sequenchr::tidy_sequence_data

color_mapping

a list of named colors where the names match the alphabet of the original sequence data

cluster_labels

optional. A vector of cluster assignments

n_col_facets

optional. If cluster_labels is provided then the number of facet columns

Value

ggplot object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(TraMineR)
data(mvad)
seqstatl(mvad[, 17:86])
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school",
                   "training")
mvad.labels <- c("employment", "further education", "higher education",
                 "joblessness", "school", "training")
mvad.seq <- seqdef(mvad, 17:86, alphabet = mvad.alphabet,
                   labels = mvad.labels, xtstep = 6)
seq_def_tidy <- tidy_sequence_data(mvad.seq)
color_mapping <- viridis::viridis_pal()(length(alphabet(mvad.seq)))
names(color_mapping) <- alphabet(mvad.seq)
plot_modal(seq_def_tidy, color_mapping)

dist_matrix <- TraMineR::seqdist(seqdata = mvad.seq, method = "DHD")
cluster_model <- hclust(d = as.dist(dist_matrix), method = 'ward.D2')
cluster_labels <- stats::cutree(cluster_model, k = 5)
plot_modal(seq_def_tidy, color_mapping, cluster_labels = cluster_labels)

joemarlo/sequenchr documentation built on Sept. 29, 2021, 12:23 a.m.