knitr::opts_chunk$set( warning = FALSE, message = FALSE, comment = FALSE )
This vignette visually explains how researchers at the USSC can use the Center's fonts and colours in their research output.
The ussc
package comes with several functions that will be useful for quantitative researchers at the Centre. As we are primarily a Tidyverse
shop, they are geared towards data visualizations made in the Tidyverse
using ggplot2
.
The functions are:
theme_ussc()
theme_ussc_dark()
scale_colour_ussc()
scale_fill_ussc()
In addition to loading the packages you would otherwise use in your analysis, load the ussc
package. In this example, I will load tidyverse
as well as ussc
.
library('ussc') library('tidyverse') ussc_fonts()
The first example uses the standard ussc theme. The font used in the title and caption is Neo Sans Pro. Other text elements on the graph default to Halis GR (see axes and legend). In this scatterplot, I have defined the colour using scale_colour_ussc()
. I call the main colour palette which is an interpolation scale ranging from the dark blue colour scheme to red. In this example, the colour scale has been reversed from red to dark blue.
example <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) + geom_point(size = 4, alpha=0.4) + theme_ussc() + labs(title="Halis GR S Bold", x="Halis GR Book: Sepal Width", y="Halis GR Book: Sepal Length", caption = "The data is from the Iris R package and is an example.") + scale_colour_ussc("main", reverse=TRUE) plot_ussc_logo(example)
ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) + geom_point(size = 4, alpha=0.4) + theme_ussc_dark() + labs(title="Halis GR S Bold", x="Halis GR Book: Sepal Width", y="Halis GR Book: Sepal Length", caption = "The data is from the Iris R package and is an example.") + scale_colour_ussc("blue", reverse=TRUE)
Researchers can specify the colour of a geom object by passing the ussc_colours() function inside the object's parentheses.
ggplot(data=iris, aes(x=Species, fill=Species)) + geom_bar(fill=ussc_colours("light blue")) + labs(x = "Species", y = "Count", title = "Bar plot of Sepal Length") + theme_ussc()
Here is an example of a faceted graph.
ggplot(mtcars, aes(mpg, hp, colour=mpg)) + geom_point() + facet_grid(cyl~gear) + labs(title='A facet_grid example') + theme_ussc() + scale_fill_ussc("main", discrete=TRUE)
ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point(aes(shape=Species), size=1.5) + xlab("Sepal Length") + ylab("Sepal Width") + ggtitle("Scatterplot with smoothers") + scale_colour_ussc("main") + theme_ussc() + geom_smooth(method="gam", formula= y~s(x, bs="cs"))
ggplot(data=ChickWeight, aes(x=Time, y=weight, color=Diet, group=Chick)) + geom_line() + labs(title = "Growth curve for individual chicks") + scale_colour_ussc("light") + theme_ussc()
box <- ggplot(data=iris, aes(x=Species, y=Sepal.Length)) box + geom_boxplot(aes(fill=Species)) + labs(title = "Iris Boxplot", y = "Sepal Length") + stat_summary(fun=mean, geom="point", shape=5, size=4) + scale_fill_ussc(reverse=TRUE) + theme_ussc()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.