knitr::opts_chunk$set(echo = TRUE) library(tidyverse) library(gmRi)
This package contains various functions for quickly accessing GMRI styles, colors, and themes.
To add a GMRI css stylesheet to an Rmarkdown File, simple use the function use_gmri_style_rmd()
and indicate which css stylesheet you wish to add.
The function: insert_gmri_header()
was created to insert a header file into an rmarkdown document or shiny app. This function was conceived to work by printing an html file located in the gmRi/inst/stylesheets
directory in-place into the .Rmd or shiny file. Currently it only works succesfully with shiny apps.
This function should be run in the first code block in the document, prior to any outputs or text. The html header will be inserted in place, so any text above it will remain above it.
# Add Header with gmRi Logo gmRi::insert_gmri_header(header_file = "gmri_logo_header.html")
Currently this function fails for rmarkdown files because it is unable to locate the .png file for the logo to display correctly. Perhaps a friendly collaborator could remedy this...
An alternative way to add a header is by including it in the www
subfolder of a .Rmd file. Then in the YAML header it can be referenced directly with:
output:
html_document:
includes:
in_header: www/header.html
before_body: www/doc_prefix.html
after_body: www/doc_suffix.html
If it references an image file make sure the path is also www/image.png
and that the file is in that folder.
OR alternatively you can add html, or images directly by including it directly via a path to a subfolder and referencing them in the subfolder.
Example: The following line of html code will attach the GMRI logo to the right of the document, the top-right when included at the start of an .Rmd doc.
<img src='www/gmri_logo.png' align="right" height="44" />
The CSS file determines what fonts, colors, sizes, spacing, and margins should be applied to different elements throughout the document. The default css file will apply the GMRI font to the headers, and apply some GMRI colors to various rmarkdown elements.
This can be placed anywhere in the document except in the setup code block. It is helpful to place this line of code with other formatting options near the top of the document.
# Access GMRI CSS Style gmRi::use_gmri_style_rmd(css_file = "gmri_rmarkdown.css")
An alternative function use_gmri_style_shiny
exists for linking a stylesheet to a Shiny Application. This function has two alternative calls for attaching a header or footer as well.
You can also access GMRI colors in ggplot through some additional functions for accessing brand colorways.
Available GMRI colors can be accessed by running gmri_cols()
without any arguments. This function can also be used to return the hex values of a desired color by name. This is helpful for manual insertion of specific colors.
mtcars$car <- rownames(mtcars) mtcars$cyl <- factor(mtcars$cyl) ggplot(mtcars, aes(cyl, mpg, color = cyl)) + geom_boxplot() + scale_color_manual( values = setNames(gmri_cols(c("gmri blue", "orange", "teal"), as_char = TRUE), c("4", "6", "8")) )
There are also 2 functions for interpolating colors using several palettes, these are scale_fill_gmri()
and scale_color_gmri()
.
ggplot(mtcars, aes(mpg, car, fill = car)) + geom_col() + scale_fill_gmri() + labs(y = NULL)
One way to add personalization is through a custom footer file. This file is written in HTML and can be attached to the bottom of the ddocument for a personalized footer. The default is an example that uses the github logo and a link to a personal github account.
# footer gmRi::insert_gmri_footer(footer_file = "akemberling_gmri_footer.html")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.