knitr::opts_chunk$set(fig.path = 'figures/')
R styles for easy NUDZ like coloring of your presentations and posters using ggplot.
The main functions you will need to style your ggplots are scale_color_nudz and scale_fill_nudz. The main arguments allow you to specify what type of palette you want (see below), if you need discrete or continuous scaling and should the order of the colors be reversed. If you opt in for base plot package, you may use the nudz_palette command to produce your own palettes.
I have a slight issue with the yellow color, as it is literaly invisible on white backgroud. So I recommend using some more reflective background fill if you opt for thhe main palette, or just use a different one :)
Beware that the main palette only contains 5 values and the other ones even less. So not the best option for exploratory analyses of XY groups :)
Installation can be easilly done with devtools.
devtools::install_github("nudz/nudz.styles")
library(ggplot2) library(nudz.styles) theme_set(theme_grey())
plt <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) + geom_point(size = 4)
plt + scale_color_nudz() + ggtitle("Main NUDZ palette")
plt + scale_color_nudz(reversed = TRUE) + ggtitle("Main reversed NUDZ palette")
plt + scale_color_nudz(n_colors = c(1,3,4)) + ggtitle("Main NUDZ palette with selected colors")
plt <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Width)) + geom_point()
plt + scale_color_nudz(discrete = FALSE) + ggtitle("Main continuous NUDZ palette") plt + scale_color_nudz(discrete = FALSE, n_colors = c(1,4)) + ggtitle("Main continuous NUDZ palette with selected colors")
Base plots are a little more troublesome as you need to do a biut of pallete preprocessing, especially for the continous values, but it can be done if you are more versed in base plotting than in ggplot.
pal <- nudz_palette() pal <- pal(length(unique(iris$Species))) plot(iris$Sepal.Width, iris$Sepal.Length, pch=19, col = pal[iris$Species]) legend("topright", col=pal, pch=19, title = "Petal Length", legend=levels(iris$Species))
pal <- nudz_palette(n_colors = c(3,4), discrete=FALSE) petal_cols <- (iris$Petal.Length-min(iris$Petal.Length))*10 # standardizing to whole numbers pal <- pal(max(petal_cols)) plot(iris$Sepal.Width, iris$Sepal.Length, pch=19, col = pal[petal_cols]) legend("topright", col=c(pal[1], pal[length(pal)]), pch=19, title = "Petal Length", legend=range(iris$Petal.Length))
show_palette(nudz_palette(palette = "main")) show_palette(nudz_palette(palette = "main", discrete = FALSE)) show_palette(nudz_palette(palette = "grey_and_blue")) show_palette(nudz_palette(palette = "grey_and_blue", discrete = FALSE)) show_palette(nudz_palette(palette = "red_and_blue")) show_palette(nudz_palette(palette = "red_and_blue", discrete = FALSE)) show_palette(nudz_palette(palette = "black_and_white")) show_palette(nudz_palette(palette = "black_and_white", discrete = FALSE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.