Skip to content
Snippets Groups Projects
Commit fee08f8e authored by Otto, Dr. Saskia's avatar Otto, Dr. Saskia
Browse files

added the panel helper functions

parent 1fb02b8a
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ export("%>%")
export(calc_vif)
export(explore_na)
export(impute)
export(panel_cor)
export(plot_statespace_ch)
export(plot_statespace_ed)
export(statespace_ch)
......
#' 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
#' @examples
#' z <- matrix(rnorm(40), ncol = 4)
#' pairs(z, upper.panel = panel_cor,
#' lower.panel = panel_lines, diag.panel = panel_hist)
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")
}
% 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.
}
\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}}
}
......@@ -13,7 +13,7 @@ trafficlight(
probs = seq(0, 1, 0.2),
quantile_type = 7,
intervals = 5,
cols = c("red", "gold", "yellow", "greenyellow", "green3"),
cols = c("green3", "greenyellow", "yellow", "gold", "red"),
main = "",
xlab = "",
ylab = "",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment