Learn R Programming

DataVisualizations (version 1.1.12)

Crosstable: Crosstable plot

Description

Presents a heatmap with values and a cross table of given Data matrix of two features and a bin width or percentualized values. In this approach the bin width is fixes. A more general way to approach this is the kernel density estimation plot of PDEscatter.

Usage

Crosstable(Data, xbins = seq(0, 100, 5), ybins = xbins, 

NormalizationFactor = 1, PlotIt = TRUE, main='Cross Table',

PlotText=TRUE,TextDigits=0,TextProbs=c(0.05,0.95))

Arguments

Data

[1:n,1:2] matrix of two features from which the cross table should be generated from

xbins

[1:k] start of k bins as a vector generated with seq of the first feature of data. Default setting assumes percentiled values between zero and 100.

ybins

[1:k] start of k bins as a vector generated with seq of the second feature of data. Normally the same for both features, other settings are only possible if the length k is equal.

NormalizationFactor

Optional, Data feautures can be seen as regular time series, e.g. 1 measurement for a minute, in this case it is useful to normalize the output, e.g. to hours, then NormalizationFactor=60

PlotIt

Optional, Plots the heatmap if TRUE. The first feature is on the x-axis (left to right) and the second on y-axis (bottom to top).

main

In case of for PlotIt=TRUE: title of plot, see title

PlotText

In case of for PlotIt=TRUE: Default TRUE: plots text in heatmap with the values of the crosstable

TextDigits

In case of for TextDigits=TRUE: integer indicating the number of decimal places to use in round.

TextProbs

In case of for TextDigits=TRUE: [1:2] numeric vector of two probabilities defining the thresholds for white text to grey text and grey text to black text, e.g. below the first threshold (Default 0.05) all values (5% of values) will be printed in white because the lowest values of the heatmap are blue. The second value of 0.95 works well if cross table has many zeros; uses quantile internally.

Value

The cross table in invisible mode which depicts the number of values (frequency) in an specific range with regard to two features.

The first feature is on the x-axis (left to right), and the second on y-axis (top to bottom) contrary to the plot where it is bottom to top.

Details

The interval in each bin is closed to the left and opened to the right. The cross table can be seen as a two-dimensional histogram. The idea to add histograms to the table is taken from [Charpentier. 2014].

References

[Charpentier. 2014] Charpentier, Arthur, ed. Computational actuarial science with R. CRC Press, 2014.

See Also

table, image, PDEscatter

Examples

Run this code
# NOT RUN {
data(ITS)
data(MTY)
#simple but not a good transformation
Data=(cbind(ITS/max(ITS),MTY/max(MTY)))*100
#choice for bins could be better
Crosstable(Data)
# }

Run the code above in your browser using DataLab