R/plot_male_choirbm.R

Defines functions plot_male_choirbm

Documented in plot_male_choirbm

#' Plot the male CHOIR Body Map
#'
#' Creates a new plot of the male CHOIR body map.
#'
#' @param df data.frame
#' @param value string
#' @return ggrob
#' @export
#'
#' @examples
#' cbm_df <- gen_example_data()
#' plot_male_choirbm(cbm_df, "value")
#'
#' @importFrom ggplot2 ggplot aes geom_polygon scale_y_reverse facet_wrap
#' @importFrom ggplot2 theme_void theme
#' @importFrom rlang .data
#'
plot_male_choirbm <- function(df, value) {
  positions <- rbind(male_front_poly_coords_df, male_back_poly_coords_df)
  datapoly <- merge(df, positions, by = "id")
  p <- ggplot(datapoly) +
    aes(x = x, y = y) +
    geom_polygon(
      aes(
        fill = .data[[value]]
        , group = .data[["id"]]
        )
      , color = "black", size = 1.5
      ) +
    scale_y_reverse() +
    facet_wrap(~.data[["group"]]) +
    theme_void() +
    theme(legend.position = "None")
  return(p)
}

Try the CHOIRBM package in your browser

Any scripts or data that you put into this service are public.

CHOIRBM documentation built on Feb. 15, 2021, 5:07 p.m.