hist_2d {SpiceFP}R Documentation

hist_2d

Description

This function results from a modification of the hist2d function of the gplots package in order to build the 2D histogram with breaks directly provided as inputs of the new function.

Usage

hist_2d(
  x,
  y,
  breaks_x,
  breaks_y,
  same.scale = FALSE,
  na.rm = TRUE,
  FUN = base::length
)

Arguments

x

either a numerical vector to be partitioned or a matrix of 2 numerical columns to be partitioned.

y

a numerical vector to be partitioned. Not required if x is a matrix.

breaks_x

a numerical vector. Contains the breaks related to x for the histogram

breaks_y

a numerical vector. Contains the breaks related to y for the histogram

same.scale

logical. Default to FALSE. If TRUE, breaks_x will be used for x and y

na.rm

logical. Default to TRUE. Indicates whether missing values should be removed

FUN

function used to summarize bin contents.

Details

The default function used for the argument FUN is the function length. When another function is used, it is applied on x, or on the first column of x if this is a two-column matrix. The lower limit of each class interval is included in the class and the upper limit is not.

Value

Using a given set of breaks per each variable, the function returns :

Hist.Values

a matrix with in rows class intervals of x and in columns class intervals of y. Contingency table is returned if FUN=length

breaks_x, breaks_y

same as the inputs of the function

Midpoints.x, Midpoints.y

the midpoints for each bin per variable

nobs.x , nobs.y

number of observations of x and y

n.bins

vector of 2 elements containing the number of bins for x and y

Examples

set.seed(45)
hist_2d(x = rnorm(1000),
        y = rnorm( 1000,5,0.1),
        breaks_x = seq(-4, 4, by =1),
        breaks_y = seq(2, 8, by =1))

[Package SpiceFP version 0.1.2 Index]