#' boxplot by groups.
#'
#' boxGroup generate boxplots to compare groups with ggplot2 library.
#'
#' @param data a dataframe.
#' @param x a column name of numeric vector in dataframe which means y.
#' @param g a column name of factor vector in dataframe which means group.
#'
#' @examples
#' test <- boxGroup(iris, 'Sepal.Length', 'Species')
#'
#' @export
boxGroup <- function(data, x, g){
data <- as.data.frame(data)
if(class(data[,x]) != "numeric"){
warning("Invalid class. \n Vecter x converted as numeric.")
data[,x] <- as.numeric(data[,x])
}
if(class(data[,g]) != 'factor'){
warning("Invalid class. \n Vecter g converted as factor.")
data[,g] <- as.factor(data[,g])
}
boxs <- ggplot2::ggplot() +
ggplot2::geom_boxplot(data = data, ggplot2::aes_string(x = g, y = x, fill = g)) +
ggplot2::theme_minimal()
return(boxs)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.