PlotDist: Side-by-side box plots, for a numerical variable, grouped by...

View source: R/numerical.R

PlotDistR Documentation

Side-by-side box plots, for a numerical variable, grouped by dateGpBp

Description

For a variable is all positive (no zeros) and has larger than 50 all distinct values, if it is highly skewed, then all box plots can be plotted under the log base 10 transformation. See the argument skewOpt for details.

Usage

PlotDist(dataFl, myVar, dateGpBp, weightNm = NULL, skewOpt = NULL)

Arguments

dataFl

A data.table of data; must be the output of the PrepData function.

myVar

The name of the variable to be plotted

dateGpBp

Name of variable the boxplots should be grouped by. Same options as dateGp. If NULL, then dateGp will be used.

weightNm

Name of the variable containing row weights, or NULL for no weights (all rows receiving weight 1).

skewOpt

Either a numeric constant or NULL. Default is NULL (no transformation). If numeric, say 5, then all box plots of a variable whose skewness exceeds 5 will be on a log10 scale if possible. Negative input of skewOpt will be converted to 3.

Value

A ggplot2 object with a box plot of myVar grouped by dateGpBp

License

Copyright 2017 Capital One Services, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Examples

data(bankData)
bankData <- PrepData(bankData, dateNm = "date", dateGp = "months", 
                     dateGpBp = "quarters")
PlotDist(dataFl = bankData, myVar = "balance", dateGpBp = "quarters")
## The following attempt to log transform will fail due to negative values,
## and the untransformed version will be returned
PlotDist(dataFl = bankData, myVar = "balance", dateGpBp = "quarters", 
         skewOpt = 3)
## This attempt should succeed, as the skew exceeds 3 and there are no 
## negative values
PlotDist(dataFl = bankData, myVar = "duration", dateGpBp = "quarters",
         skewOpt = 3)

capitalone/otvPlots documentation built on March 15, 2024, 8:25 a.m.