Last updated: 2024-03-25


# Load ggplot2
library(ggplot2)

# Load ggmitji 
library(ggmitji)

Fill top strips

# Example plot from https://ggplot2.tidyverse.org/reference/facet_grid.html
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p <- p + facet_grid(cols = vars(drv))
p

fill_strips_top(p = p, colors = c("red", "blue", "yellow"))

Fill right strips

# Example plot from https://ggplot2.tidyverse.org/reference/facet_grid.html
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p <- p + facet_grid(rows = vars(drv))
p

fill_strips_right(p = p, colors = c("red", "blue", "yellow"))

Fill bottom strips

# Example plot from https://ggplot2.tidyverse.org/reference/facet_grid.html
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p <- p + facet_grid(cols = vars(drv), switch = "x")
p

fill_strips_bottom(p = p, colors = c("red", "blue", "yellow"))

Fill left strips

# Example plot from https://ggplot2.tidyverse.org/reference/facet_grid.html
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p <- p + facet_grid(rows = vars(drv), switch = "y")
p

fill_strips_left(p = p, colors = c("red", "blue", "yellow"))

Fill all strips

Top and right strips

# Example plot from https://ggplot2.tidyverse.org/reference/facet_grid.html
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p <- p + facet_grid(rows = vars(drv), cols=vars(fl))
p

# first the top strips and then the right strips
fill_strips(p = p, side = c("top", "right"), 
            colors = c("gray10","gray30", "gray50","gray70","gray90", 
                       "red", "blue", "yellow"))

Bottom and left strips

# Example plot from https://ggplot2.tidyverse.org/reference/facet_grid.html
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p <- p + facet_grid(rows = vars(drv), cols=vars(fl), switch = "both")
p

# first the bottom strips and then the left strips
fill_strips(p = p, side = c("bottom", "left"), 
            colors = c("gray10","gray30", "gray50","gray70","gray90", 
                       "red", "blue", "yellow"))