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
+1
View File
@@ -1,3 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^README\.Rmd$
+19
View File
@@ -1,2 +1,21 @@
# Generated by roxygen2: do not edit by hand
export(add_logo)
export(add_logo_ga)
export(get_png)
export(has_caption)
export(make_logo_grob)
export(measure_caption)
export(na_zero)
export(plot_jpeg)
export(pretty_count)
export(pretty_per)
export(safe_max)
export(theme_civilytics)
importFrom(ggplot2,theme)
importFrom(graphics,rasterImage)
importFrom(grid,rasterGrob)
importFrom(gridExtra,arrangeGrob)
importFrom(jpeg,readJPEG)
importFrom(png,readPNG)
importFrom(stringr,str_count)
+57 -5
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)) +
#' 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("data/civilytics_logo.png"), xmin = 0.825, xmax = 1)
annotation_custom(get_png(system.file("img", "civilytics_logo.png",
package="civilytics")), xmin = 0.825, xmax = 1)
logo_grob
}
+12 -7
View File
@@ -37,28 +37,33 @@ pretty_per <- function(x, ndigit = 1) {
options(knitr.kable.NA = "-")
#' Title
#' Zero out missing values
#'
#' @param x
#' @param x a numeric vector with missing values
#'
#' @return
#' @return a numeric vector with missing values replaced by 0
#' @export
#'
#' @examples
#' na_zero(1:10)
#' na_zero(c(NA, NA, 2:10))
na_zero <- function(x) {
x[is.na(x)] <- 0
return(x)
}
#' Title
#' Prettify count data
#' Make integers propertly formatted as strings which include commas suitable for printing
#' @param x a numeric vector
#'
#' @param x
#'
#' @return
#' @return a character vector with commas introduced in place positions in the numbers
#' @export
#'
#' @examples
#' pretty_count(10)
#' pretty_count(1000)
#' pretty_count(1e8)
pretty_count <- function(x) {
x <- prettyNum(x, big.mark = ",")
return(x)
+25
View File
@@ -0,0 +1,25 @@
# civilytics
<!-- badges: start -->
<!-- badges: end -->
The goal of civilytics is to ...
## Installation
You can install the released version of civilytics from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("civilytics")
```
## Example
This is a basic example which shows you how to solve a common problem:
``` r
library(civilytics)
## basic example code
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

+17
View File
@@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logo.R
\name{add_logo}
\alias{add_logo}
\title{Title}
\usage{
add_logo(plot, logo, margin_param = NULL)
}
\arguments{
\item{margin_param}{}
}
\value{
}
\description{
Title
}
+17
View File
@@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logo.R
\name{add_logo_ga}
\alias{add_logo_ga}
\title{Title}
\usage{
add_logo_ga(plot_list, logo, nrow = 1, widths = NULL, margin_param = NULL)
}
\arguments{
\item{margin_param}{}
}
\value{
}
\description{
Title
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

+17
View File
@@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logo.R
\name{get_png}
\alias{get_png}
\title{Title}
\usage{
get_png(filename)
}
\arguments{
\item{filename}{}
}
\value{
}
\description{
Title
}
+17
View File
@@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logo.R
\name{has_caption}
\alias{has_caption}
\title{Title}
\usage{
has_caption(gg)
}
\arguments{
\item{gg}{}
}
\value{
}
\description{
Title
}
+14
View File
@@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logo.R
\name{make_logo_grob}
\alias{make_logo_grob}
\title{Get a Civilytics Logo grob}
\usage{
make_logo_grob()
}
\value{
}
\description{
Get a Civilytics Logo grob
}
+17
View File
@@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logo.R
\name{measure_caption}
\alias{measure_caption}
\title{Title}
\usage{
measure_caption(gg)
}
\arguments{
\item{gg}{}
}
\value{
}
\description{
Title
}
+21
View File
@@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{na_zero}
\alias{na_zero}
\title{Zero out missing values}
\usage{
na_zero(x)
}
\arguments{
\item{x}{a numeric vector with missing values}
}
\value{
a numeric vector with missing values replaced by 0
}
\description{
Zero out missing values
}
\examples{
na_zero(1:10)
na_zero(c(NA, NA, 2:10))
}
+20
View File
@@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logo.R
\name{plot_jpeg}
\alias{plot_jpeg}
\title{Title}
\usage{
plot_jpeg(path, add = FALSE, upscale = TRUE)
}
\arguments{
\item{upscale}{}
}
\value{
}
\description{
Title
}
\examples{
img <- readJPEG(system.file("img","Rlogo.jpg",package="jpeg"))
}
+24
View File
@@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{pretty_count}
\alias{pretty_count}
\title{Prettify count data
Make integers propertly formatted as strings which include commas suitable for printing}
\usage{
pretty_count(x)
}
\arguments{
\item{x}{a numeric vector}
}
\value{
a character vector with commas introduced in place positions in the numbers
}
\description{
Prettify count data
Make integers propertly formatted as strings which include commas suitable for printing
}
\examples{
pretty_count(10)
pretty_count(1000)
pretty_count(1e8)
}
+25
View File
@@ -0,0 +1,25 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{pretty_per}
\alias{pretty_per}
\title{Prettify proportion data
Make data expresed as proportions print out as prettily formatted characters with percentages}
\usage{
pretty_per(x, ndigit = 1)
}
\arguments{
\item{x}{a numeric vector of proportions to convert to percentages}
\item{ndigit}{a vector of length 1 indicating the number of digits to display in the percent}
}
\value{
}
\description{
Prettify proportion data
Make data expresed as proportions print out as prettily formatted characters with percentages
}
\examples{
pretty_per(0.2, ndigit = 1)
pretty_per(c(0.2, 0.332423, 0.4, 0.342342), ndigit = 2)
}
+23
View File
@@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{safe_max}
\alias{safe_max}
\title{Safe maximum
Take the max but ignore missing values}
\usage{
safe_max(x)
}
\arguments{
\item{x}{a numeric vector which may contain NA values}
}
\value{
the maximum non-missing value
}
\description{
Safe maximum
Take the max but ignore missing values
}
\examples{
safe_max(1:10)
safe_max(c(1:10, NA)) # 10
}
+24
View File
@@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme.R
\name{theme_civilytics}
\alias{theme_civilytics}
\title{Title}
\usage{
theme_civilytics(
font_size = 14,
font_family = "",
line_size = 0.5,
rel_small = 12/14,
rel_tiny = 11/14,
rel_large = 16/14
)
}
\arguments{
\item{rel_large}{}
}
\value{
}
\description{
Title
}