Colour palettes and plotting themes for ggplot2
that resembles 80s
guitar. Incredible example below of Racer X
You can install ggshredR
from GitHub by running the following:
devtools::install_github("hendersontrent/ggshredR")
The theme works by adding the function call to the end of your ggplot2
code:
library(ggplot2)
library(ggshredR)
ggplot(mpg, aes(x = cyl, y = cty)) +
geom_point(size = 3) +
labs(title = "Cylinders vs city mpg") +
theme_shredR(grids = TRUE)
The colour palette built into the package is presented below:
library(scales)
scales::show_col(ggshredR:::shredR_palette)
Use scale_colour_shredR()
to apply the theme for colour parameters.
ggplot(mpg, aes(x = displ, y = cty, colour = drv, size = cyl)) +
geom_point(alpha = 0.5) +
labs(title = "Engine disp vs city mpg by drivetrain and cyl") +
scale_colour_shredR() +
theme_shredR(grids = TRUE)
Fitting regression models such as generalised additive models (GAM) to charts also looks very shreddy.
library(mgcv)
ggplot(mpg, aes(x = displ, y = cty, colour = drv, size = cyl)) +
geom_smooth(aes(group = 1), formula = y ~ s(x), method = "gam", size = 1) +
geom_point(alpha = 0.5) +
labs(title = "Engine disp vs city mpg by drivetrain and cyl") +
scale_colour_shredR() +
theme_shredR(grids = TRUE)
And scale_fill_shredR()
to apply the theme for fill parameters.
library(dplyr)
library(magrittr)
mpg %>%
group_by(drv) %>%
summarise(cty = mean(cty)) %>%
ungroup()%>%
ggplot(aes(x = reorder(drv, -cty), y = cty, fill = drv)) +
geom_col() +
labs(title = "Average city mpg by drivetrain") +
scale_fill_shredR() +
theme_shredR()
This is achieved through the make_it_shred
function. This function
lets you specify the surname of a shred guitar legend who was prominent
in the 80s.
ggplot(mpg, aes(x = displ, y = cty, colour = drv, size = cyl)) +
make_it_shred(shred_lord = "Vai") +
geom_smooth(aes(group = 1), formula = y ~ s(x), method = "gam", size = 1) +
geom_point(alpha = 0.5) +
labs(title = "Engine disp vs city mpg by drivetrain and cyl") +
scale_colour_shredR() +
theme_shredR(grids = FALSE)