add package doco skeleton and images

This commit is contained in:
Jared Knowles
2020-02-13 17:09:03 -05:00
parent 1f41a4560d
commit f5f288974f
30 changed files with 1071 additions and 13 deletions
+58 -6
View File
@@ -1,5 +1,3 @@
#' Title
#'
#' @param path
@@ -9,7 +7,7 @@
#' @return
#' @export
#' @importFrom jpeg readJPEG
#'
#' @importFrom graphics rasterImage
#' @examples
#' img <- readJPEG(system.file("img","Rlogo.jpg",package="jpeg"))
plot_jpeg <- function(path, add=FALSE, upscale = TRUE)
@@ -43,6 +41,18 @@ get_png <- function(filename) {
}
#' Title
#'
#' @param plot
#' @param logo
#' @param margin_param
#'
#' @return
#' @importFrom ggplot2 theme
#' @importFrom gridExtra arrangeGrob
#' @export
#'
#' @examples
add_logo <- function(plot, logo, margin_param = NULL) {
if(has_caption(plot)) {
# convert the caption size to a negative number and on the "pt" scale
@@ -63,6 +73,15 @@ add_logo <- function(plot, logo, margin_param = NULL) {
padding = unit(0.1, "line"))
}
#' Title
#'
#' @param gg
#'
#' @return
#' @importFrom stringr str_count
#' @export
#'
#' @examples
measure_caption <- function(gg) {
if (has_caption(gg)) {
stringr::str_count(gg$labels$caption, pattern = "\n") + 1
@@ -71,10 +90,33 @@ measure_caption <- function(gg) {
}
}
#' Title
#'
#' @param gg
#'
#' @return
#' @export
#'
#' @examples
has_caption <- function(gg) {
any(names(gg$labels) == "caption")
}
#' Title
#'
#' @param plot_list
#' @param logo
#' @param nrow
#' @param widths
#' @param margin_param
#'
#' @return
#' @importFrom gridExtra arrangeGrob
#' @importFrom ggplot2 theme
#' @export
#'
#' @examples
add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL, margin_param = NULL) {
# Change position of logo depending on if plot has a caption
if (!is.null(margin_param)) {
@@ -102,6 +144,16 @@ add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL, margin_param =
}
logo_grob <- ggplot(mapping = aes(x = 0:1, y = 1)) +
theme_void() +
annotation_custom(get_png("data/civilytics_logo.png"), xmin = 0.825, xmax = 1)
#' Get a Civilytics Logo grob
#'
#' @return
#' @export
#'
#' @examples
make_logo_grob <- function() {
logo_grob <- ggplot(mapping = aes(x = 0:1, y = 1)) +
theme_void() +
annotation_custom(get_png(system.file("img", "civilytics_logo.png",
package="civilytics")), xmin = 0.825, xmax = 1)
logo_grob
}