knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo = TRUE, message = FALSE, warning = FALSE )
library(fishpals) library(ggplot2)
This vignette presents examples of all the themes included in the package.
The fishpals
package provides fish-inspired color palettes and some lightweight ggplot
themes that we hope will be especially useful to scientists when preparing reports, presentations, and publications.
fishpals
into Rfishpals
is a pretty trivial package, so it's unlikely it will ever be submitted to CRAN. You can install the fishpals
package using the install_github
function from either the remotes
or devtools
packages:
devtools::install_github("fishsciences/fishpals", build_vignettes = TRUE) library(fishpals)
To see all the palettes included in the fishpals
package, use getpals()
:
getpals()
To view a particular palette, call it by name with viewpals()
viewpals("surgewrasse")
To see a full list of all the colors in each palette, use get_fishpals_cols()
:
get_fishpals_cols()
scale_*_fishpals()
functionsfishpals
is designed to integrate with ggplot2
code, and so provides two ggplot2
scale functions for displaying its custom color palettes. To use them, map a variable to a color aesthetic and call the appropriate scale function: scale_fill_fishpals()
or scale_color_fishpals()
:
ggplot(warpbreaks) + geom_boxplot(aes(x = wool, y = breaks, color = wool, fill = wool), alpha = 0.5, width = 0.5, show.legend = FALSE) + facet_wrap(~tension, labeller = labeller(tension = c("L" = "Low", "M" = "Medium", "H" = "High") )) + scale_color_fishpals(discrete = TRUE) + scale_fill_fishpals(discrete = TRUE) + labs(x = "Wool type", y = "Number of breaks", title = "Breaks ~ wool type + tension level")
The default color palette is "cfs". To use a different one, just call it by name:
ggplot(warpbreaks, aes(x = wool, y = breaks)) + geom_jitter(aes(color = tension), size = 2.5, width = 0.15) + scale_color_fishpals("adultchinook")
theme_report()
This theme is designed to have good properties when knitting to pdf or to Microsoft Word. These properties include:
ggplot(mpg) + geom_point(aes(x = displ, y = hwy)) + theme_report() + labs(y = "Miles per gallon", x = "Engine displacement (L)", title = "Highway mpg ~ Engine displacement") ggplot(economics_long, aes(x = date, y = value01)) + geom_line(aes(color = variable), size = 0.5) + theme_report() + scale_color_fishpals() + guides(color = guide_legend(title = NULL)) + labs(x = "Date", y = "Value index", title = "Scaled economic indices ~ year") ggplot(warpbreaks) + geom_boxplot(aes(x = wool, y = breaks, color = wool, fill = wool), alpha = 0.5, width = 0.5, show.legend = FALSE) + facet_wrap(~tension, labeller = labeller(tension = c("L" = "Low", "M" = "Medium", "H" = "High") )) + scale_color_fishpals(discrete = TRUE) + scale_fill_fishpals(discrete = TRUE) + theme_report(inner_border = FALSE) + labs(x = "Wool type", y = "Number of breaks", title = "Breaks ~ wool type + tension level")
theme_pres()
This theme is designed to have good default properties for presentations. These properties include:
ggplot(mpg) + geom_point(aes(x = displ, y = hwy)) + theme_pres() + labs(y = "Miles per gallon", x = "Engine displacement (L)", title = "Highway mpg ~ Engine displacement") ggplot(economics_long, aes(x = date, y = value01)) + geom_line(aes(color = variable), size = 0.5) + theme_pres() + scale_color_fishpals() + guides(color = guide_legend(title = NULL)) + labs(x = "Date", y = "Value index", title = "Scaled economic indices ~ year") ggplot(warpbreaks) + geom_boxplot(aes(x = wool, y = breaks, color = wool, fill = wool), alpha = 0.5, width = 0.25, show.legend = FALSE) + facet_wrap(~tension, labeller = labeller(tension = c("L" = "Low", "M" = "Medium", "H" = "High") ), ncol = 1) + scale_color_fishpals(discrete = TRUE) + scale_fill_fishpals(discrete = TRUE) + theme_pres() + labs(x = "Wool type", y = "Number of breaks", title = "Breaks ~ wool type + tension level")
theme_pub()
has some default font sizes and axis options often used in publications:
ggplot(economics_long, aes(x = date, y = value01)) + geom_line(aes(color = variable), size = 0.5) + theme_pub() + scale_color_brewer(palette = 6) + # using color brewer black and white palette for demonstration guides(color = guide_legend(title = NULL)) + labs(x = "Date", y = "Value index", title = "Scaled economic indices ~ year") + theme(legend.position = "bottom")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.