diff --git a/NAMESPACE b/NAMESPACE index e800283ea546e4cc98deebd22368186296d4bda8..8f2dbd6ba28582332e6945de9bcd7dd9aa26bb37 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,8 @@ export(calc_vif) export(explore_na) export(impute) export(panel_cor) +export(panel_hist) +export(panel_lines) export(plot_statespace_ch) export(plot_statespace_ed) export(statespace_ch) diff --git a/R/panel_cor.R b/R/panel_cor.R deleted file mode 100644 index 90b6f527044fa1e91643f2c765c3facdab3d4458..0000000000000000000000000000000000000000 --- a/R/panel_cor.R +++ /dev/null @@ -1,40 +0,0 @@ -#' Show correlation coefficient in pairs plot -#' -#' This and the other functions are utility functions for the pairs plot. -#' \code{panel_cor} shows the Pearson product-moment correlation coefficient in -#' the selected panels. \code{panel_lines} shows the regression line and -#' \code{panel_hist} histograms. -#' -#' @param x numeric vector -#' @param y numeric vector - -#' @seealso \code{\link{pairs}} -#' @export - -panel_cor <- function(x, y) { - par(usr = c(0, 1, 0, 1)) - r <- stats::cor(x, y, use = "pairwise.complete.obs") - txt <- format(r, digits = 1) - text(0.5, 0.5, txt, cex = 0.9/strwidth(txt) * abs(r)) -} - -#' @rdname panel_cor -panel_lines <- function (x, y) { - points(x, y, bg = NA, cex = 1) - sel <- is.finite(x) & is.finite(y) - if (any(sel)){ - lml <- stats::lm(y[sel] ~ x[sel]) - abline(lml, col = "blue")} -} - - -#' @rdname panel_cor -panel_hist <- function(x) { - usr <- par("usr") - par(usr = c(usr[1:2], 0, 1.5) ) - h <- hist(x, plot = FALSE) - breaks <- h$breaks - nB <- length(breaks) - y <- h$counts / max(h$counts) - rect(breaks[-nB], 0, breaks[-1], y, col = "grey80") -} diff --git a/R/panel_funcs.R b/R/panel_funcs.R new file mode 100644 index 0000000000000000000000000000000000000000..7602c3067e8bdc521dfd00895a69e6377e71abba --- /dev/null +++ b/R/panel_funcs.R @@ -0,0 +1,48 @@ +#' Show correlation coefficient, histogram or regression lines in pairs plot +#' +#' \code{panel_cor}, \code{panel_lines} and \code{panel_hist} are utility functions +#' for the pairs plot. \code{panel_cor} shows the Pearson product-moment correlation +#' coefficient in the selected panels. \code{panel_lines} shows the regression line and +#' \code{panel_hist} histograms. +#' +#' @param x numeric vector +#' @param y numeric vector +#' @name panel_funcs + +#' @seealso \code{\link{pairs}} +#' @examples +#' z <- matrix(rnorm(40), ncol = 4) +#' pairs(z, upper.panel = panel_cor, +#' lower.panel = panel_lines, diag.panel = panel_hist) +NULL + +#' @rdname panel_funcs +#' @export +panel_cor <- function(x, y) { + par(usr = c(0, 1, 0, 1)) + r <- stats::cor(x, y,use = "pairwise.complete.obs") + txt <- format(r, digits = 1) + text(0.5, 0.5, txt, cex = 0.9/strwidth(txt) * abs(r)) +} + +#' @rdname panel_funcs +#' @export +panel_lines <- function (x, y) { + points(x, y, bg = NA, cex = 1) + sel <- is.finite(x) & is.finite(y) + if (any(sel)){ + lml <- stats::lm(y[sel] ~ x[sel]) + abline(lml, col = "blue")} +} + +#' @rdname panel_funcs +#' @export +panel_hist <- function(x) { + usr <- par("usr") + par(usr = c(usr[1:2], 0, 1.5) ) + h <- hist(x, plot = FALSE) + breaks <- h$breaks + nB <- length(breaks) + y <- h$counts / max(h$counts) + rect(breaks[-nB], 0, breaks[-1], y, col="grey80") +} diff --git a/man/panel_cor.Rd b/man/panel_cor.Rd deleted file mode 100644 index ed53cf36c7a21d68f52cd60695954177e43d1d00..0000000000000000000000000000000000000000 --- a/man/panel_cor.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/panel_cor.R -\name{panel_cor} -\alias{panel_cor} -\alias{panel_lines} -\alias{panel_hist} -\title{Show correlation coefficient in pairs plot} -\usage{ -panel_cor(x, y) - -panel_lines(x, y) - -panel_hist(x) -} -\arguments{ -\item{x}{numeric vector} - -\item{y}{numeric vector} -} -\description{ -This and the other functions are utility functions for the pairs plot. -\code{panel_cor} shows the Pearson product-moment correlation coefficient in -the selected panels. \code{panel_lines} shows the regression line and -\code{panel_hist} histograms. -} -\seealso{ -\code{\link{pairs}} -} diff --git a/man/panel_funcs.Rd b/man/panel_funcs.Rd new file mode 100644 index 0000000000000000000000000000000000000000..2b33b8d7bd4e815a9019b241ac6fec5c4700684b --- /dev/null +++ b/man/panel_funcs.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/panel_funcs.R +\name{panel_funcs} +\alias{panel_funcs} +\alias{panel_cor} +\alias{panel_lines} +\alias{panel_hist} +\title{Show correlation coefficient, histogram or regression lines in pairs plot} +\usage{ +panel_cor(x, y) + +panel_lines(x, y) + +panel_hist(x) +} +\arguments{ +\item{x}{numeric vector} + +\item{y}{numeric vector} +} +\description{ +\code{panel_cor}, \code{panel_lines} and \code{panel_hist} are utility functions +for the pairs plot. \code{panel_cor} shows the Pearson product-moment correlation +coefficient in the selected panels. \code{panel_lines} shows the regression line and +\code{panel_hist} histograms. +} +\examples{ +z <- matrix(rnorm(40), ncol = 4) +pairs(z, upper.panel = panel_cor, +lower.panel = panel_lines, diag.panel = panel_hist) +} +\seealso{ +\code{\link{pairs}} +}