knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", echo = TRUE, eval = TRUE )
library(fishpals) library(ggplot2)
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 trivial, so it's unlikely to ever be submitted to CRAN. You can install it using either devtools::install_github()
or the install_github
function from the remotes
package:
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) + 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("adultchinook", discrete = TRUE) + scale_fill_fishpals("adultchinook", discrete = TRUE) + labs(x = "Wool type", y = "Number of breaks", title = "Breaks ~ wool type + tension level")
theme_report()
This theme is designed to have good properties when knitting to pdf or to Microsoft Word. These properties include:
inner_border = TRUE
).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(inner_border = FALSE) + 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() + labs(x = "Wool type", y = "Number of breaks", title = "Breaks ~ wool type and tension level")
theme_pres()
This theme is designed with good defaults for presentations. These 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") ), nrow = 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()
This theme has default font sizes and axis options that are 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.