R/sales.R

Defines functions mario_plot_sales

Documented in mario_plot_sales

#' Plot sales of Mario games.
#'
#' @param type Type of plot ("bar" or "pie").
#' @return ggplot of sales
#'
#' @export
#'
#' @examples
#' mario_plot_sales("bar")
#' mario_plot_sales("pie")
mario_plot_sales <- function(type = "bar") {
  sales <- Mario::sales
  if (type == "bar") {
    base <- ggplot2::ggplot(data=sales, ggplot2::aes(x=Game, y=Sales))
    plot <- base + ggplot2::geom_bar(stat="identity")
  } else if (type == "pie") {
    base <- ggplot2::ggplot(data=sales, ggplot2::aes(x="", y=Sales, fill=Game))
    bar <- base + ggplot2::geom_bar(width=1, stat="identity")
    plot <- bar + ggplot2::coord_polar("y", start=0)
    plot <- plot + ggplot2::theme_void() + ggplot2::scale_fill_brewer(palette="Set2")
  }
  return (plot)
}


# theme(axis.text.x = element_text(angle = 90))
pjoachims/mario documentation built on July 4, 2020, 12:05 a.m.