Skip to content

Commit

Permalink
added option to swap axes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgimond committed Jul 25, 2024
1 parent d81061c commit 9208aa6
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 10 deletions.
25 changes: 21 additions & 4 deletions R/eda_dens.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#' @param ylab Y variable label. Ignored if \code{x} is a dataframe.
#' @param show.par Boolean determining if parameters such as power
#' transformation or formula should be displayed.
#' @param switch Boolean determining if the axes should be swapped. Only applies
#' to dataframe input. Ignored if vectors are passed to the function.
#' @param ... Arguments passed to the \code{stats::density()} function.
#'
#' @details This function will generate overlapping density plots with the first
Expand All @@ -51,14 +53,29 @@


eda_dens <- function(x, y, fac = NULL, p = 1L, tukey = FALSE, fx = NULL,
fy = NULL, grey = 0.6, col = "red", size = 0.8, show.par= TRUE,
alpha = 0.4, xlab = NULL, ylab = NULL, legend = TRUE, ...) {
fy = NULL, grey = 0.6, col = "red", size = 0.8,
show.par= TRUE, alpha = 0.4, xlab = NULL, ylab = NULL,
switch = FALSE, legend = TRUE, ...) {

# Extract data
if("data.frame" %in% class(x)){
val <- eval(substitute(y), x)
fac <- eval(substitute(fac), x)
g <- unique(fac)
#fac <- eval(substitute(fac), x)
fac <- as.factor(eval(substitute(fac), x))
fac <- droplevels(fac)

# Get level order (determines axes order)
if(is.null(levels(fac))) {
g <- unique(fac)
} else {
g <- levels(fac)
}

# Switch axes if requested
if (switch == TRUE){
g <- rev(g)
}

if( length(g) != 2){
stop(paste("Column", fac, "has", length(g),
"unique values. It needs to have two exactly."))
Expand Down
26 changes: 23 additions & 3 deletions R/eda_qq.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#' IQR. Two values are needed.
#' @param l.val Quantiles to define the quantile line parameters. Defaults to
#' the mid 75\% of values. Two values are needed.
#' @param switch Boolean determining if the axes should be swapped. Only applies
#' to dataframe input. Ignored if vectors are passed to the function.
#' @param xlab X label for output plot. Ignored if \code{x} is a dataframe.
#' @param ylab Y label for output plot. Ignored if \code{x} is a dataframe.
#' @param title Title to add to plot.
Expand Down Expand Up @@ -148,7 +150,8 @@ eda_qq <- function(x, y = NULL, fac = NULL, norm = FALSE, sym = FALSE, p = 1L,
plot = TRUE, show.par = TRUE, grey = 0.6, pch = 21,
p.col = "grey50", p.fill = "grey80", size = 0.8, alpha = 0.8,
q = TRUE, b.val = c(0.25,0.75), l.val = c(0.125, 0.875),
xlab = NULL, ylab = NULL, title = NULL, t.size = 1.2, ...) {
switch = FALSE, xlab = NULL, ylab = NULL, title = NULL,
t.size = 1.2, ...) {

# Parameters check
if (length(b.val)!= 2) stop("The b.val argument must have two values.")
Expand All @@ -170,14 +173,31 @@ eda_qq <- function(x, y = NULL, fac = NULL, norm = FALSE, sym = FALSE, p = 1L,
# Extract data ----
if("data.frame" %in% class(x)){
val <- eval(substitute(y), x)
fac <- eval(substitute(fac), x)
#fac <- eval(substitute(fac), x)
fac <- as.factor(eval(substitute(fac), x))
fac <- droplevels(fac)

if (is.null(fac))
stop("You need to pass a valid factor column to the fac parameter")
g <- unique(fac)

# Get level order (determines axes order)
if(is.null(levels(fac))) {
g <- unique(fac)
} else {
g <- levels(fac)
}

# Switch axes if requested
if (switch == TRUE){
g <- rev(g)
}

if( length(g) != 2){
stop(paste("Column", fac, "has", length(g),
"unique values. It needs to have two exactly."))
}

# Extract X and Y values
x <- val[fac == g[1]]
y <- val[fac == g[2]]
xlab <- g[1]
Expand Down
Binary file modified docs/reference/eda_dens-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_dens-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion docs/reference/eda_dens.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified docs/reference/eda_qq-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/eda_qq-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions docs/reference/eda_qq.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/eda_dens.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/eda_qq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9208aa6

Please sign in to comment.