Numero (version 1.2.0)

nroPlot: Plot a self-organizing map

Description

Create a graphical interface for selecting subgroups from multiple map colorings simultaneously.

Usage

nroPlot(elements, colors, labels = NULL, values = NULL, subplot = NULL,
        interactive = FALSE, clear = NULL, file = NULL)

Arguments

elements

A data frame with K rows and six columns that contains the district positions of a self-organizing map.

colors

A character vector with K elements or a K x N matrix of hexadecimal color codes as strings.

labels

A character vector with K elements or a K x N matrix of district labels.

values

A vector with K elements or a K x N matrix of district values.

subplot

A two-element vector that sets out the number of rows and columns for a grid layout of multiple colorings.

clear

If TRUE, all graphics devices are cleared when the plot is refreshed.

interactive

If TRUE, an interactive version of the plot is launched.

file

If non-empty, the figure is saved as a Scalable Vector Graphics file instead of plotting on the R device.

Value

A data frame with K rows that contains the topology and subgrouping information.

Details

The input elements must follow the topology format nroKohonen(), but may also contain the columns REGION, REGION.label and REGION.color that specify the name for a subset of districts, the single character labels to be shown on top of those districts, and the color of the labels. The input can also be the list object as in the output format of nroKohonen().

Some non-alphanumeric characters are not supported and will be automatically converted to '_'. Too long labels or column names will be truncated.

The default value for clear is TRUE to prevent multiple plot windows from accumulating within the RStudio. If you are running R from the terminal or using detached devices, setting clear will retain the current window when refreshing.

References

Gao S, Mutter S, Casey AE, M<U+00E4>kinen V-P (2018) Numero: a statistical framework to define multivariable subgroups in complex population-based datasets, Int J Epidemiology, https://doi.org/10.1093/ije/dyy113

Examples

Run this code
# NOT RUN {
# Import data.
fname <- system.file("extdata", "finndiane.txt", package = "Numero")
dataset <- read.delim(file = fname)

# Detect binary columns.
dataset <- nroPreprocess(dataset, method = "")

# Prepare training data.
trvars <- c("CHOL", "HDL2C", "TG", "CREAT", "uALB")
trdata <- scale.default(dataset[,trvars])

# K-means clustering.
km <- nroKmeans(data = trdata)

# Self-organizing map.
sm <- nroKohonen(seeds = km)
sm <- nroTrain(som = sm, data = trdata)

# Assign data points into districts.
matches <- nroMatch(centroids = sm, data = trdata)

# Select a subset of variables and detect binary data.
vars <- c("AGE", "MALE", "uALB", "CHOL", "DIAB_KIDNEY", "DECEASED")
selected <- nroPreprocess(dataset[,vars], method = "")

# Calculate district averages for seleted variables.
vars <- c("AGE", "MALE", "uALB", "CHOL", "DIAB_KIDNEY", "DECEASED")
planes <- nroAggregate(topology = sm, districts = matches, data = selected)

# Estimate statistics.
stats <- nroPermute(som = sm, districts = matches, data = selected)

# Set visuals.
colrs <- nroColorize(values = planes, amplitudes = stats)
labls <- nroLabel(topology = sm, values = planes)

# Plot colorings on screen.
nroPlot(elements = sm, colors = colrs, labels = labls)
# }

Run the code above in your browser using DataLab