#' My ggplot2 template
#'
#'
#' @param flip logical value to whether `ggplot2::coord_flip()` is implemented.
#' @param family specify font registered in `grDevices::windowsFonts()`
#' @param size list of font size. `title` is axis.title and legend.title.
#' `text` is axis.text and legend.text. `caption` is plot.caption.
#' @param legend_key_size specify legend.key.size. Unit is "cm."
#'
#' @importFrom ggplot2 theme_minimal
#' @importFrom ggplot2 theme
#' @importFrom ggplot2 element_blank
#' @importFrom ggplot2 element_text
#' @importFrom ggplot2 unit
#' @importFrom ggplot2 element_line
#'
#' @return return an object whose class is `gg` and `theme`.
#'
#' @export
#+
ggtemp <- function(flip = FALSE,
family = NULL,
size = list(
title = 13,
text = 9,
caption = 11
),
legend_key_size = 1) {
my_theme <- theme_minimal(base_family = family) +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
axis.text = element_text(
color = "black", size = size$text, family = family
),
axis.title = element_text(size = size$title, family = family),
axis.ticks.length = unit(0.25, "cm"),
axis.ticks.x = element_line(),
axis.ticks.y = element_line(),
axis.line = element_line(),
legend.text = element_text(size = size$text, family = family),
legend.key.size = unit(legend_key_size, "cm"),
legend.title = ggplot2::element_text(size = size$title),
legend.position = "bottom",
plot.caption = ggplot2::element_text(size = size$caption)
)
if (flip) {
my_theme <- my_theme +
theme(
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_line()
)
}
return(my_theme)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.