plotJenks: R function for plotting univariate classification using...

View source: R/plotJenks.R

plotJenksR Documentation

R function for plotting univariate classification using Jenks' natural break method

Description

The function allows to break a dataset down into a user-defined number of breaks and to nicely plot the results, adding a number of other relevant information. Implementing the Jenks' natural breaks method, it allows to find the best arrangement of values into different classes.

Usage

plotJenks(data, n = 3, brks.cex = 0.7, top.margin = 10, dist = 5)

Arguments

data

Vector storing the data.

n

Number of classes in which the dataset must be broken down (3 by default).

brks.cex

Adjusts the size of the labels used in the returned plot to display the classes' break-points.

top.margin

Adjusts the distance of the labels from the top margin of the returned chart.

dist

Adjusts the distance of the labels from the dot used to display the data points.

Details

The function produces a chart in which the values of the input variable are arranged on the x-axis in ascending order, while the index of the individual observations is reported on the y-axis. Vertical dotted red lines correspond to the optimal break-points which best divide the input variable into the selected classes. The break-points (and their values) are reported in the upper part of the chart, onto the corresponding break lines. Also, the chart's subtitle reports the Goodness of Fit value relative to the selected partition, and the partition which correspond to the maximum GoF value.

Value

The function returns a list containing the following components:

  • $info: information about whether or not the method created non-unique breaks

  • $classif: created classes and number of observations falling in each class

  • $classif$brks: classes' break-points

  • $breaks$max.GoF: number of classes at which the maximum GoF is achieved

  • $class.data: dataframe storing the values and the class in which each value actually falls into

Examples

#create a toy dataset
mydata <- rnorm(100, 30, 10)

# performs the analysis, using 6 as number of desired classes,
# and store the results in the 'res' object
res <- plotJenks(mydata, n=6)


GmAMisc documentation built on March 18, 2022, 6:32 p.m.