diff --git a/R/eda_dens.R b/R/eda_dens.R index 0546282..14f5d54 100755 --- a/R/eda_dens.R +++ b/R/eda_dens.R @@ -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 @@ -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) @@ -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 @@ -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) diff --git a/docs/reference/eda_3pt.html b/docs/reference/eda_3pt.html index 1326d55..699c409 100755 --- a/docs/reference/eda_3pt.html +++ b/docs/reference/eda_3pt.html @@ -203,15 +203,12 @@
hsratio <- eda_3pt(cars, speed, dist)
-
hsratio <- eda_3pt(cars, speed, dist, py = 1/3, ylab=expression("Dist"^{1/3}))
-
#' # This next example models gas consumption as a function of engine displacement.
# It applies a transformation to both variables via the px and py arguments.
eda_3pt(mtcars, disp, mpg, px = -1/3, py = -1,
ylab = "gal/mi", xlab = expression("Displacement"^{-1/3}))
-
#> $slope1
#> [1] -0.3633401
#>
diff --git a/docs/reference/eda_add.html b/docs/reference/eda_add.html
index b529058..2d9e0a3 100755
--- a/docs/reference/eda_add.html
+++ b/docs/reference/eda_add.html
@@ -111,7 +111,6 @@ Examples#> 37.285126 -5.344472
Mr <- eda_rline(mtcars, x=wt, y=mpg)
eda_add(Mr, l.col = "blue")
-
#> $a
#> [1] 37.61522
#>
diff --git a/docs/reference/eda_bipow.html b/docs/reference/eda_bipow.html
index 7bcc8bc..689eb68 100755
--- a/docs/reference/eda_bipow.html
+++ b/docs/reference/eda_bipow.html
@@ -108,13 +108,10 @@ Examplesdata(cars)
# Example 1
eda_bipow(dat = cars, x = speed, y = dist)
-
# Custom powers
eda_bipow(dat = cars, x = speed, y = dist, p = c(-1, -0.5, 0, 0.5, 1))
-
# Adopt Tukey transformation
eda_bipow(dat = cars, x = speed, y = dist, tukey = TRUE, p = c(-1, -0.5, 0, 0.5, 1))
-
# A basic boxplot. The outlier is labeled with the row number by default.
eda_boxls(mtcars,mpg, cyl, type="none")
-
# A basic boxplot. The outlier is labeled with its own value.
eda_boxls(mtcars,mpg, cyl, type="none", out.txt=mpg )
-
# Boxplot equalized by level. Note that the outlier text is labeled with its
# original value.
eda_boxls(mtcars,mpg, cyl, type="l", out.txt=mpg )
-
#> ========================
#> Note that the data have been equalized with "type" set to "l".
#> ========================
# Boxplots equalized by level and spread
eda_boxls(mtcars,mpg, cyl, type="ls", out.txt=mpg )
-
#> ========================
#> Note that the data have been equalized with "type" set to "ls".
#> ========================
# Hide outlier
eda_boxls(mtcars,mpg, cyl, type="ls", out.txt=mpg , outlier=FALSE)
-
#> ========================
#> Note that the data have been equalized with "type" set to "ls".
#> ========================
@@ -226,24 +221,20 @@ Examples# Equalizing level helps visualize increasing spread with increasing
# median value
eda_boxls(iris, Sepal.Length, Species, type = "l", out.txt=Sepal.Length)
-
#> ========================
#> Note that the data have been equalized with "type" set to "l".
#> ========================
# For long factor level names, flip plot
eda_boxls(iris, Sepal.Length, Species, out.txt=Sepal.Length , horiz = TRUE)
-
# By default, plots are ordered by their medians.
singer <- lattice::singer
eda_boxls(singer, height, voice.part, out.txt=height, horiz = TRUE)
-
# To order by top quartile, set reorder.stat to "upper"
eda_boxls(singer, height, voice.part, out.txt=height, horiz = TRUE,
reorder.stat = "upper")
-