Wraping of title, caption and subtitle pass to theming
This commit is contained in:
parent
e8a6734d0f
commit
6ff42bac73
4 changed files with 15 additions and 16 deletions
|
|
@ -24,6 +24,7 @@ Imports:
|
|||
grDevices,
|
||||
glue,
|
||||
scales,
|
||||
stringr
|
||||
stringr,
|
||||
ggtext
|
||||
Suggests: knitr, sf, tmap
|
||||
VignetteBuilder: knitr
|
||||
|
|
|
|||
11
R/bar.R
11
R/bar.R
|
|
@ -16,15 +16,12 @@
|
|||
#' @param caption Plot caption. Default to NULL.
|
||||
#' @param add_text TRUE or FALSE. Add the value as text.
|
||||
#' @param add_text_suffix If percent is FALSE, should we add a suffix to the text label?
|
||||
#' @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().
|
||||
#'
|
||||
#' @return A bar chart
|
||||
#'
|
||||
#' @export
|
||||
bar <- function(df, x, y, group = NULL, flip = TRUE, percent = TRUE, position = "dodge", alpha = 1, x_title = NULL, y_title = NULL, group_title = NULL, title = NULL, subtitle = NULL, caption = NULL, add_text = FALSE, add_text_suffix = "", title_wrap = 60, subtitle_wrap = 60, caption_wrap = 120, theme = theme_reach()){
|
||||
bar <- function(df, x, y, group = NULL, flip = TRUE, percent = TRUE, position = "dodge", alpha = 1, x_title = NULL, y_title = NULL, group_title = NULL, title = NULL, subtitle = NULL, caption = NULL, add_text = FALSE, add_text_suffix = "", theme = theme_reach()){
|
||||
|
||||
# To do :
|
||||
# - automate bar width and text size, or at least give the flexibility and still center text
|
||||
|
|
@ -44,9 +41,9 @@ bar <- function(df, x, y, group = NULL, flip = TRUE, percent = TRUE, position =
|
|||
|
||||
# Add title, subtitle, caption, x_title, y_title
|
||||
g <- g + ggplot2::labs(
|
||||
title = stringr::str_wrap(title, title_wrap),
|
||||
subtitle = stringr::str_wrap(subtitle, subtitle_wrap),
|
||||
caption = stringr::str_wrap(caption, caption_wrap),
|
||||
title = title,
|
||||
subtitle = subtitle,
|
||||
caption = caption,
|
||||
x = x_title,
|
||||
y = y_title,
|
||||
color = group_title,
|
||||
|
|
|
|||
11
R/point.R
11
R/point.R
|
|
@ -13,15 +13,12 @@
|
|||
#' @param title Plot title. Default to NULL.
|
||||
#' @param subtitle Plot subtitle. 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().
|
||||
#'
|
||||
#' @return A bar chart
|
||||
#'
|
||||
#' @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, title_wrap = 60, subtitle_wrap = 60, caption_wrap = 120, 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, theme = theme_reach()){
|
||||
|
||||
# To do :
|
||||
# - automate bar width and text size, or at least give the flexibility and still center text
|
||||
|
|
@ -41,9 +38,9 @@ point <- function(df, x, y, group = NULL, flip = TRUE, alpha = 1, size = 1, x_ti
|
|||
|
||||
# Add title, subtitle, caption, x_title, y_title
|
||||
g <- g + ggplot2::labs(
|
||||
title = stringr::str_wrap(title, title_wrap),
|
||||
subtitle = stringr::str_wrap(subtitle, subtitle_wrap),
|
||||
caption = stringr::str_wrap(caption, caption_wrap),
|
||||
title = title,
|
||||
subtitle = subtitle,
|
||||
caption = caption,
|
||||
x = x_title,
|
||||
y = y_title,
|
||||
color = group_title,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,11 @@ theme_reach <- function(
|
|||
plot.caption.position = "plot",
|
||||
# Text sizes
|
||||
axis.text = ggplot2::element_text(size = axis_text_size),
|
||||
axis.title = ggplot2::element_text(size = axis_title_size)
|
||||
axis.title = ggplot2::element_text(size = axis_title_size),
|
||||
# Wrap title
|
||||
plot.title = ggtext::element_textbox_simple(),
|
||||
plot.subtitle = ggtext::element_textbox_simple(),
|
||||
plot.caption = ggtext::element_textbox_simple()
|
||||
)
|
||||
|
||||
# Axis lines ?
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue