plot_akstats: Plot of cluster groups.

Description Usage Arguments Details Value References Examples

View source: R/plot_akstats.R

Description

Takes the 'ak_object' from the 'akclustr' as input and produce either the 'line' plot or 'stacked' histogram.

Usage

1
2
3
4
5
6
7
8
plot_akstats(
  ak_object,
  k = 3,
  reference = 1,
  n_quant = 4,
  type = "lines",
  y_scaling = "fixed"
)

Arguments

ak_object

An output of akclustr function. The object contains individual trajectories and their cluster solution(s) at the specified values of k. Also, includes the optimal value of k based on the criterion specified. at (different) values of k the traj.

k

[integer] k cluster to generate its solution.

reference

[numeric] Specifying the reference line from which the direction of each group is measured. Options are: 1: slope of mean trajectory, 2: slope of medoid trajectory, 3: slope of a horizontal line (i.e. slope = 0). Default: 1.

n_quant

[numeric] Number of equal intervals (quantiles) to create between the reference line (R) and the medoids (M) of the most-diverging groups of both sides of (R). Default is 4 - meaning quartile subdivisions on each side of (R). In this scenario, the function returns the quartile in which the medoid of each group falls. This result can be used to further categorize the groups into 'classes'. For example, groups that fall within the 1st quartile may be classified as 'Stable' groups (Adepeju et al. 2021).

type

[character] plot type. Available options are: "lines" and "stacked".

y_scaling

[character] works only if type="lines". y_scaling set the vertical scales of the cluster panels. Options are: "fixed": uses uniform scale for all panels, "free": uses variable scales for panels.

Details

Generates the plots of cluster groups - same plots generated by the 'show_plots' argument of print_akstats. The function draw from the functionalities of the ggplot2 library. For a more customized visualisation, we recommend that users deploy ggplot2 directly (Wickham H. (2016)).

Value

A plot showing group membership or sizes (proportion) and statistics.

References

1. Adepeju, M. et al. (2021). Anchored k-medoids: A novel adaptation of k-medoids further refined to measure inequality in the exposure to crime across micro places, doi: 10.1007/s42001-021-00103-1.

2. Wickham H. (2016). Elegant graphics for Data Analysis. Spring-Verlag New York (2016).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
data(traj)

trajectry <- data_imputation(traj, id_field = TRUE, method = 1,
replace_with = 1, fill_zeros = FALSE)

print(trajectry$CompleteData)

trajectry <- props(trajectry$CompleteData, id_field = TRUE)

aksolution <- akclustr(trajectry, id_field = TRUE,
method = "linear", k = c(3,5), crit='Calinski_Harabasz')

plot_akstats(aksolution, k = 4, type="lines",
y_scaling="fixed")

plot_akstats(aksolution, k = 4, reference = 1,
n_quant = 4, type="stacked")

akmedoids documentation built on April 13, 2021, 9:07 a.m.