## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
options(rmarkdown.html_vignette.check_title = FALSE)

## ----setup--------------------------------------------------------------------
library(CHOIRBM)
library(ggplot2)

## ----load_data----------------------------------------------------------------
# loading the validation data included in the CHOIRBM package
data(validation)
head(validation)

## ----mf_split-----------------------------------------------------------------
male_data <- validation[validation[["gender"]] == "Male", ]
female_data <- validation[validation[["gender"]] == "Female", ]

## ----data_proc_m--------------------------------------------------------------
male_bodymap_list <- lapply(male_data[["bodymap_regions_csv"]], string_to_map)
male_bodymap_df <- agg_choirbm_list(male_bodymap_list)

# we want to visualize the percent endorsement, so divide the values by
# the size of the data set and multiply by 100
male_bodymap_df[["perc"]] <- male_bodymap_df[["value"]] /
  nrow(male_data) * 100
head(male_bodymap_df)

## ----data_proc_f--------------------------------------------------------------
female_bodymap_list <- lapply(
  female_data[["bodymap_regions_csv"]]
  , string_to_map
)

female_bodymap_df <- agg_choirbm_list(female_bodymap_list)

# we want to visualize the percent endorsement, so divide the values by
# the size of the data set and multiply by 100
female_bodymap_df[["perc"]] <- female_bodymap_df[["value"]] /
  nrow(female_data) * 100
head(female_bodymap_df)

## ----plot_m_cbm---------------------------------------------------------------
plot_male_choirbm(male_bodymap_df, value = "perc") +
  theme(legend.position = "bottom") +
  labs(fill = "Percent Endorsement")

## ----plot_f_cbm---------------------------------------------------------------
plot_female_choirbm(female_bodymap_df, value = "perc") +
  theme(legend.position = "bottom") +
  labs(fill = "Percent Endorsement")

