library(theme.usq) library(ggplot2) knitr::opts_chunk$set(eval = TRUE, collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 5, fig.align = "center")
The goal of theme.usq
is to provide
University of Southern Queensland (USQ) staff and students
a quick and easy way to apply USQ colours and typography to graphs created in R
using the base graphics
package or ggplot2
while providing clear graphs
for reports and presentations. All of the colours provided are defined in USQ's
Visual Identity Colour Palette, but do not all appear in the same order to
maintain usability for the purposes of graphing.
This package has been tested on macOS, Ubuntu Linux and USQ computers using Windows 7. For Linux users, if you have not installed the MS Core Fonts, you will need to do that for this package to function properly and generate the graphs with the proper typography. Windows and macOS users should be ready to go with just the installation of this package.
Load the library using the following command in R.
library(theme.usq)
To view a list of named colours in this package, simply type:
usq_colours
The resulting list shows the hexadecimal colour, e.g. "#ffd100", and it's name, "usq yellow". The names may be used to specify the colours at any time when plotting.
Colours are grouped into convenient palettes as well. The palettes may be used when plotting. To see the palettes and colours included in each of them, simply type:
usq_palettes
Visualise the USQ primary palette to see the colours included.
vis_palette(usq_palettes$primary, "primary")
Create a vector of 16 colours based on USQ's primary colour palette.
usq_pal(p = "primary", r = FALSE, a = 1)(16)
Visualise the 16 interpolated colours from above,
vis_palette(usq_palettes$primary, "primary interpolated to 25", num = 16)
Following are a few examples of theme.usq's
capabilities.
Plot plot car weights by miles per gallon.
plot_usq(x = mtcars$wt, y = mtcars$mpg)
Plot car weights by miles per gallon and facet by Transmission
(0 = automatic,
1 = manual) using the scale_colour_usq()
setting discrete = TRUE
and using
the cool
palette to use blue USQ colours for the plot.
p1 <- ggplot(data = mtcars) + geom_point(aes( x = wt, y = mpg, colour = factor(gear) )) + scale_colour_usq(discrete = TRUE, palette = "cool") + facet_wrap(~ am) p1
Now add the theme_usq()
to the graph.
p1 + theme_usq()
Using the theme.usq's
theme_usq()
for ggplot2
, plot values
using the scale_fill_usq()
to use USQ colours for continuous values in the
graph.
p2a <- ggplot(data = faithfuld, aes(x = waiting, y = eruptions)) + geom_raster(aes(fill = density), interpolate = TRUE) + scale_fill_usq("warm", discrete = FALSE) + theme_usq() p2a
p2b <- ggplot(data = faithfuld, aes(x = waiting, y = eruptions)) + geom_raster(aes(fill = density), interpolate = TRUE) + scale_fill_usq("cool", discrete = FALSE) + theme_usq() p2b
theme_usq()
can be used with any colour palette that you wish to use, while
still applying the graph styling and typography to the graph.
Use the default ggplot2
colour scheme to fill the density plot while
using the theme_usq()
to theme the graph.
p3 <- ggplot(data = faithfuld, aes(x = waiting, y = eruptions)) + geom_raster(aes(fill = density), interpolate = TRUE) + theme_usq() p3
hist_usq(diamonds$carat)
p4 <- ggplot(data = diamonds, aes(x = carat)) + geom_histogram(fill = usq_cols("usq charcoal")) + theme_usq() p4
Plot the highway miles per gallon (mpg) of 38 popular car models in the US by class of car.
boxplot_usq(mpg$hwy ~ mpg$class)
p5 <- ggplot(data = mpg, aes(x = class, y = hwy)) + geom_boxplot(alpha = 0.75, fill = usq_cols("usq charcoal"), colour = usq_cols("usq charcoal")) + theme_usq() p5
Use the USQ colours to fill the box-plots while using drv
(e.g., 4-wheel
drive, front-wheel drive or rear-wheel drive) for the box-plot colour.
p5.1 <- ggplot(data = mpg, aes(x = class, y = hwy)) + geom_boxplot(aes(fill = drv), colour = usq_cols("usq charcoal")) + scale_fill_usq("primary") + theme_usq() p5.1
discrete colours for each variable of interest. While possible to do with base R
graphics, ggplot2
simplifies the process greatly, so it is the only
example provided and suggested for use.
p6 <- ggplot(data = as.data.frame(economics_long), aes(x = date, y = value01, colour = variable)) + geom_line() + scale_colour_usq("bright") + theme_usq() p6
Plot the areas in thousands of square miles of landmasses which exceed 10,000 sqm.
barplot_usq(islands, col = "cool gray")
Plot the areas in thousands of square miles of landmasses which exceed 10,000
sqm.
Note the use of coord_flip()
to rotate the axis so that the x-axis labels
do not need to be rotated.
library(tibble) islands_df <- as.data.frame(islands) islands_df <- rownames_to_column(islands_df, "name") ggplot(data = islands_df, aes(x = name, y = islands)) + geom_bar(stat = "identity", colour = usq_cols("cool gray"), fill = usq_cols("cool gray")) + theme_usq() + coord_flip()
The default settings for theme_usq()
are fine for printed materials such as
reports, but if you wish to use it in a presentation you can use the
ggplot2
option base_size =
to increase the size of the fonts, points
and lines in the graphs.
As an example, using base_size = 24
helps ensure that the graphs are legible
on a standard sized PowerPoint slide when exported at a size of 33.87mm x
19.05mm, using ggsave()
, for a 16x9 presentation slide that fills the whole
slide.
p8 <- ggplot(data = mpg, aes(x = class, y = hwy)) + geom_boxplot(fill = usq_cols("usq charcoal"), colour = usq_palette("usq charcoal"), alpha = 0.75) + theme_usq(base_size = 24) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) ggsave("slide_p7.png", width = 33.87, height = 19.05, units = "cm", dpi = 150)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.