Add wraps for title, subtitle, and caption

This commit is contained in:
gnoblet 2022-12-21 11:41:58 -05:00
parent bdb44ed82f
commit e8a6734d0f

View file

@ -1,4 +1,4 @@
#' @title Simple bar chart #' @title Simple point chart
#' #'
#' @param df A data frame. #' @param df A data frame.
#' @param x A numeric column. #' @param x A numeric column.
@ -13,12 +13,15 @@
#' @param title Plot title. Default to NULL. #' @param title Plot title. Default to NULL.
#' @param subtitle Plot subtitle. Default to NULL. #' @param subtitle Plot subtitle. Default to NULL.
#' @param caption Plot caption. Default to NULL. #' @param caption Plot caption. Default to NULL.
#' @param title_wrap Wrap title, number of characters.
#' @param subtitle_wrap Wrap subtitle, number of characters.
#' @param caption_wrap Wrap caption, number of characters.
#' @param theme Whatever theme. Default to theme_reach(). #' @param theme Whatever theme. Default to theme_reach().
#' #'
#' @return A bar chart #' @return A bar chart
#' #'
#' @export #' @export
point <- function(df, x, y, group = NULL, flip = TRUE, alpha = 1, size = 1, x_title = NULL, y_title = NULL, group_title = NULL, title = NULL, subtitle = NULL, caption = NULL, theme = theme_reach()){ point <- function(df, x, y, group = NULL, flip = TRUE, alpha = 1, size = 1, x_title = NULL, y_title = NULL, group_title = NULL, title = NULL, subtitle = NULL, caption = NULL, title_wrap = 60, subtitle_wrap = 60, caption_wrap = 120, theme = theme_reach()){
# To do : # To do :
# - automate bar width and text size, or at least give the flexibility and still center text # - automate bar width and text size, or at least give the flexibility and still center text
@ -38,9 +41,9 @@ point <- function(df, x, y, group = NULL, flip = TRUE, alpha = 1, size = 1, x_ti
# Add title, subtitle, caption, x_title, y_title # Add title, subtitle, caption, x_title, y_title
g <- g + ggplot2::labs( g <- g + ggplot2::labs(
title = title, title = stringr::str_wrap(title, title_wrap),
subtitle = subtitle, subtitle = stringr::str_wrap(subtitle, subtitle_wrap),
caption = caption, caption = stringr::str_wrap(caption, caption_wrap),
x = x_title, x = x_title,
y = y_title, y = y_title,
color = group_title, color = group_title,