Skip to content

update bargraph to close #629 #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Imports:
latticeExtra,
ggdendro,
gridExtra
Suggests:
Suggests:
lubridate,
fastR,
magrittr,
Expand All @@ -43,15 +43,15 @@ VignetteBuilder: knitr
Author: Randall Pruim <[email protected]>, Daniel T. Kaplan
<[email protected]>, Nicholas J. Horton <[email protected]>
Maintainer: Randall Pruim <[email protected]>
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
11 changes: 10 additions & 1 deletion R/bargraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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"
Expand All @@ -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)) ) )
Expand All @@ -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, ...)
}
6 changes: 5 additions & 1 deletion man/bargraph.Rd

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

4 changes: 3 additions & 1 deletion man/xhistogram.Rd

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