R/freqOrdPlot.R

Defines functions freqOrdPlot

Documented in freqOrdPlot

#' freqOrdPlot
#' @param dfData a data.frame object.
#' @param dfColName a string indicating the name of the column to plot.
#' @param main a character string indicating an overall title for the plot. If not specified then the column name is used as the title.
#' @param xlab a character string indicating a label for the x-axis.
#' @param ablineV a number indicating the x-coordinate of a vertical line (i.e. parallel to the y-axis) to be added to the cumulative distribution plot. The number should be within the range of values that column \code{dfColName} of \code{dfData} takes.  
#' @param ablineH a number between 0.0 and 1.0 indicating the y-coordinate of a horizontal line (i.e. parallel to the x-axis) to be added to the cumulative distribution plot.
#' @return freqOrdPlot returns a plot of the empirical cumulative frequency distribution of the data in column \code{dfColName} of \code{dfData} considering the length of \code{dfColName} as total population. It also provides an option to add horizontal and vertical lines by specifying the parameters \code{ablineH} and \code{ablineV} respectively.
#' @description freqOrdPlot takes as input a data.frame object \code{dfData}, a column name \code{dfColName}, a character string (\code{main}) for the overall title of the plot, a character string for the x-axis label, and returns a plot of the empirical cumulative frequency distribution of the data in column \code{dfColName} of \code{dfData} considering the length of \code{dfColName} as total population. It also provides an option to add horizontal and vertical lines by specifying the parameters \code{ablineH} and \code{ablineV} respectively.
#' @examples
#' freqOrdPlot(iris,"Sepal.Length")
#' freqOrdPlot(iris,"Sepal.Width")
#' freqOrdPlot(iris,"Sepal.Length",,,,0.7)
#' @export
freqOrdPlot<-function(dfData,dfColName,main=dfColName,xlab="",ablineV=NULL,ablineH=NULL,...)
{
  plot(dfData[,dfColName][order(dfData[,dfColName])],(1:length(dfData[,dfColName]))/length(dfData[,dfColName]),
       main=main,xlab=xlab,ylab="Cumulative probability",...)  
  abline(v=ablineV)
  abline(h=ablineH)
}
lwTools/agriTrf documentation built on March 26, 2020, 12:09 a.m.