diff --git a/DESCRIPTION b/DESCRIPTION index d49c6488..5338c3e3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,7 @@ Imports: latticeExtra, ggdendro, gridExtra -Suggests: +Suggests: lubridate, fastR, magrittr, @@ -43,15 +43,15 @@ VignetteBuilder: knitr Author: Randall Pruim , Daniel T. Kaplan , Nicholas J. Horton Maintainer: Randall Pruim -Description: Data sets and utilities from Project MOSAIC (http://mosaic-web.org) used - to teach mathematics, statistics, computation and modeling. Funded by the - NSF, Project MOSAIC is a community of educators working to tie together - aspects of quantitative work that students in science, technology, - engineering and mathematics will need in their professional lives, but - which are usually taught in isolation, if at all. +Description: Data sets and utilities from Project MOSAIC (http://mosaic-web.org) + used to teach mathematics, statistics, computation and modeling. Funded by the + NSF, Project MOSAIC is a community of educators working to tie together aspects + of quantitative work that students in science, technology, engineering and + mathematics will need in their professional lives, but which are usually taught + in isolation, if at all. License: GPL (>=2) LazyLoad: yes LazyData: yes URL: https://github.com/ProjectMOSAIC/mosaic BugReports: https://github.com/ProjectMOSAIC/mosaic/issues -RoxygenNote: 5.0.1 +RoxygenNote: 5.0.1.9000 diff --git a/R/bargraph.R b/R/bargraph.R index 48760c7a..6f5ddd2d 100644 --- a/R/bargraph.R +++ b/R/bargraph.R @@ -20,6 +20,8 @@ #' @param xlab a character vector of length one used for the x-axis label #' @param type one of \code{"frequency"}, \code{"count"}, \code{"percent"}, or \code{"proportion"} #' indicating what type of scale to use. Unique prefixes are sufficient. +#' @param auto.key a logical expression indicating whether a legend should be automatically produced +#' @param scales is a list determining how the x- and y-axes are drawn #' @return a trellis object describing the plot #' @seealso \code{\link[lattice]{barchart}} #' @details \code{bargraph(formula, data=data, ...)} works by creating a new data frame from \code{xtabs(formula, data=data)} @@ -48,6 +50,8 @@ bargraph <- function(x, data = parent.frame(), groups = NULL, horizontal = FALSE ylab = ifelse(horizontal, "", type), xlab = ifelse(horizontal, type, ""), type = c("count", "frequency", "proportion", "percent"), + auto.key = TRUE, + scales = list(), ...) { type <- match.arg(type) if (type == "frequency") type <- "count" @@ -65,6 +69,8 @@ bargraph <- function(x, data = parent.frame(), groups = NULL, horizontal = FALSE xtab <- xtab %>% dplyr::mutate(..X.. = xtab[, 1]) sgroups <- substitute(groups) + + if (horizontal) { if (! is.null(condition(x))){ formula <- as.formula( paste("..X.. ~ ", lastvar, " | ", deparse(condition(x)) ) ) @@ -77,10 +83,13 @@ bargraph <- function(x, data = parent.frame(), groups = NULL, horizontal = FALSE } else { formula <- as.formula(paste(lastvar, " ~ ..X..")) } + if(length(scales) == 0 ){ + scales = list(x = list(rot = 30)) + } } if (xlab == "" && ! horizontal) { xlab <- names(dimnames(xtab0))[1] } if (ylab == "" && horizontal) { ylab <- names(dimnames(xtab0))[1] } barchart(formula, data = xtab, groups = eval(sgroups), - origin=origin, ylab = ylab, xlab = xlab, ...) + origin=origin, ylab = ylab, xlab = xlab, auto.key = auto.key, scales=scales, ...) } diff --git a/man/bargraph.Rd b/man/bargraph.Rd index c8af6800..ce60f103 100644 --- a/man/bargraph.Rd +++ b/man/bargraph.Rd @@ -7,7 +7,7 @@ bargraph(x, data = parent.frame(), groups = NULL, horizontal = FALSE, origin = 0, ylab = ifelse(horizontal, "", type), xlab = ifelse(horizontal, type, ""), type = c("count", "frequency", - "proportion", "percent"), ...) + "proportion", "percent"), auto.key = TRUE, scales = list(), ...) } \arguments{ \item{x}{a formula describing the plot} @@ -30,6 +30,10 @@ a different kind of plot as the results may be misleading.} \item{type}{one of \code{"frequency"}, \code{"count"}, \code{"percent"}, or \code{"proportion"} indicating what type of scale to use. Unique prefixes are sufficient.} +\item{auto.key}{a logical expression indicating whether a legend should be automatically produced} + +\item{scales}{is a list determining how the x- and y-axes are drawn} + \item{\dots}{additional arguments passed to \code{\link[lattice]{barchart}}} } \value{ diff --git a/man/xhistogram.Rd b/man/xhistogram.Rd index d9908f93..5cbe1c54 100644 --- a/man/xhistogram.Rd +++ b/man/xhistogram.Rd @@ -45,7 +45,9 @@ When using the \pkg{mosaic} package defaults, \item{gcol}{color of guidelines} -\item{fcol}{fill color for histogram rectangles} +\item{fcol}{fill colors for histogram rectangles when using \code{groups}. +(Use \code{col}, which is passed through to \code{\link{panel.histogram}}(), when +not using `groups`.} \item{dmath}{density function for density curve overlay}