Skip to content

Commit

Permalink
Added xaxis argument to eda_dens()
Browse files Browse the repository at this point in the history
  • Loading branch information
mgimond committed Nov 1, 2024
1 parent 7099108 commit 0c86796
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
20 changes: 16 additions & 4 deletions R/eda_dens.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
#' @param alpha Fill transparency (0 = transparent, 1 = opaque). Only applicable
#' if \code{rgb()} is not used to define fill colors.
#' @param legend Boolean determining if a legend should be added to the plot.
#' @param xlab X variable label. Ignored if \code{x} is a dataframe.
#' @param ylab Y variable label. Ignored if \code{x} is a dataframe.
#' @param xlab X variable label. Ignored if \code{x} is a dataframe. This is
#' not the x-axis label!
#' @param ylab Y variable label. Ignored if \code{x} is a dataframe. This is
#' not the y-axis label!
#' @param xaxis Label for x-axis. Defaults to \code{"Value"}.
#' @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
Expand Down Expand Up @@ -55,11 +58,14 @@
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,
switch = FALSE, legend = TRUE, ...) {
xaxis = NULL, switch = FALSE, legend = TRUE, ...) {

# Extract data
if("data.frame" %in% class(x)){
val <- eval(substitute(y), x)
if(is.null(xaxis)){
xaxis <- as.character(substitute(fac))
}
#fac <- eval(substitute(fac), x)
fac <- as.factor(eval(substitute(fac), x))
fac <- droplevels(fac)
Expand Down Expand Up @@ -91,6 +97,10 @@ eda_dens <- function(x, y, fac = NULL, p = 1L, tukey = FALSE, fx = NULL,
if(is.null(ylab)){
ylab = substitute(y)
}
if(is.null(xaxis)){
xaxis = "Value"
}

}

# Re-express data if required
Expand Down Expand Up @@ -169,7 +179,9 @@ eda_dens <- function(x, y, fac = NULL, p = 1L, tukey = FALSE, fx = NULL,
axis(2,col=plotcol, col.axis=plotcol, labels=TRUE, las=1, hadj = 0.8,
tck = -0.02)
mtext("Density", side=3, adj= -0.1 , col=plotcol, padj = -1)
title(xlab = "Value", line = 1.8, col.lab=plotcol)

# Add x-axis label
title(xlab = xaxis, line = 1.8, col.lab=plotcol)

if(show.par == TRUE){
mtext(side = 3, text=paste0("p=",p,";",fx," ",fy,sep=""), adj=1, cex = 0.65)
Expand Down
3 changes: 0 additions & 3 deletions docs/reference/eda_3pt.html

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

1 change: 0 additions & 1 deletion docs/reference/eda_add.html

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

3 changes: 0 additions & 3 deletions docs/reference/eda_bipow.html

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

9 changes: 0 additions & 9 deletions docs/reference/eda_boxls.html

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

Loading

0 comments on commit 0c86796

Please sign in to comment.