Skip to content

Commit

Permalink
allow user to decide if fill the boxes by xvar when drawing boxplot. …
Browse files Browse the repository at this point in the history
…Default draws all boxes to be blue.
  • Loading branch information
gmlang committed Feb 14, 2018
1 parent d9e8b0b commit 45e226e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions R/mk_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @param df A data frame.
#' @return
#' \code{function(xvar, yvar, xlab="", ylab="", main="", legend=TRUE,
#' \code{function(xvar, yvar, fillby="1", xlab="", ylab="", main="", legend=TRUE,
#' add_label=TRUE, lab_at_top=TRUE, vpos=0)}
#' \itemize{
#' \item xvar : string, x variable.
Expand Down Expand Up @@ -50,12 +50,12 @@
#' p = plt("year_cat", "budget", ylab="boxoffice", legend=F)
#' scale_axis(p, scale="log10")
mk_boxplot = function(df) {
function(xvar, yvar, xlab="", ylab="", main="", legend=T,
function(xvar, yvar, fillby="1", xlab="", ylab="", main="", legend=T,
add_label=T, lab_at_top=T, vpos=0) {
xvar_type = class(df[[xvar]])
# make plot
if (xvar_type %in% c("character", "factor"))
p = ggplot2::ggplot(df, ggplot2::aes_string(x=xvar, y=yvar, fill=xvar)) +
p = ggplot2::ggplot(df, ggplot2::aes_string(x=xvar, y=yvar, fill=fillby)) +
ggplot2::geom_boxplot() +
ggplot2::stat_summary(fun.y=mean, geom="point", shape=5, size=2)
else
Expand Down
2 changes: 1 addition & 1 deletion man/mk_boxplot.Rd

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

0 comments on commit 45e226e

Please sign in to comment.