#' plot_boxplot_facet
#'
#' plot a box plot
#'
#' @param df_ data frame or tibble
#' @param factor_ factor on the x-axis
#' @param value_var response variable
#' @param facet_var optional: a second factor to split the plot with facet
#' @param xlab xlab
#' @param ylab ylab
#' @param my_title title of the plot
#'
#' @return
#' @export
#'
#' @examples
#' plot_boxplot_facet(pbmc_div_mut, "status", "mutations")
plot_boxplot_facet <- function(df_, factor_, value_var, facet_var=NULL, xlab=NULL, ylab=NULL, my_title=NULL) {
my_theme <- igfuns::my_theme()
p <-
ggplot(df_, aes(x=!!sym(factor_), y=!!sym(value_var), color=!!sym(factor_))) +
geom_boxplot() +
my_theme
if (!is.null(facet_var)) {
p <- p + facet_grid(cols = vars(!!sym(facet_var)))
}
if (!is.null(xlab))
p <- p + xlab(xlab)
if (!is.null(ylab))
p <- p + ylab(ylab)
if (!is.null(my_title))
p <- p + ggtitle(my_title)
p
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.