{tvthemes 1.3.0} is on CRAN: ‘Steven Universe’-themed color palettes for ggplot2!

[This article was first published on R by R(yo), and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Welcome back to {tvthemes}, an R package for color palettes and ggplot2 themes from your favorite TV shows! The 1.3.0 release is now on CRAN. It’s been a very long time since the last update to {tvthemes}. Even version 1.2.0 was just updates on the back-end of things to implement Github Actions into my package workflow.

I’ve been shifting my focus more heavily over to soccer analytics stuff since the pandemic started as an alternative way of escaping reality. While I did start watching Steven Universe and had mostly completed the palettes for it a year ago, I never actually released it… so that’s the main addition to version 1.3.0. What y’all get are more than 30 (thirty!) palettes based off of the various colorful “Gem” characters from Steven Universe!

Let’s get started!

library(tvthemes)
library(ggplot2)
library(dplyr)
library(extrafont)
loadfonts(quiet = TRUE)

You can use the scales::show_col() function to take a peek at the palettes available inside stevenUniverse_palette. Character palettes range from friends…!

scales::show_col(tvthemes:::stevenUniverse_palette$Peridot)

scales::show_col(tvthemes:::stevenUniverse_palette$LapisLazuli)

scales::show_col(tvthemes:::stevenUniverse_palette$Sardonyx)

scales::show_col(tvthemes:::stevenUniverse_palette$Bismuth)

… to foes!

scales::show_col(tvthemes:::stevenUniverse_palette$Jasper)

scales::show_col(tvthemes:::stevenUniverse_palette$Aquamarine)

scales::show_col(tvthemes:::stevenUniverse_palette$Spinel)

scales::show_col(tvthemes:::stevenUniverse_palette$Topaz)

You can also show all 31 at once in the ‘Plots’ pane using the code below. It will show the last palette in the list after you run it but you can click the ‘back arrow’ to flip through the others. It might be easier if you run it inside a RMarkdown chunk as that way it’ll show all the output in a single window.

pal_name <- names(tvthemes:::stevenUniverse_palette)

show_all_pal <- function(pal_name) {
  exp_pal <- paste0("tvthemes:::stevenUniverse_palette$", pal_name)
  
  pal_call <- eval(expr = parse(text = exp_pal))
  
  return(scales::show_col(pal_call))
}

purrr::walk(pal_name, ~ show_all_pal(pal_name = .x))

Now here are some examples using actual plots!

data <- gapminder::gapminder %>% 
  filter(country %in% c("Ireland", "Italy", "Turkey", "France", "Germany", 
                        "Brazil", "Mexico", "Sweden")) %>% 
  mutate(year = as.Date(paste(year, "-01-01", sep = "", format = '%Y-%b-%d')),
         image = "")

ggplot(data = data, aes(x = year, y = gdpPercap, fill = country)) +
  geom_area(alpha = 0.9) +
  scale_x_date(expand = c(0, 0), breaks = data$year, date_labels = "%Y") +
  scale_y_continuous(expand = c(0, 0), labels = scales::dollar) +
  scale_fill_stevenUniverse(palette = "Steven", reverse = FALSE) +
  labs(title = stringr::str_wrap("I just can't believe you guys are like a bazillion years old! How do you find a cake big enough for all that many candles?", width = 70),
       subtitle = "Square pizza!? What's wrong with this crazy state!?",
       caption = "Yay, Lion!",
       x = "Years Since The Gem War", y = "Revenue (in $) from COOKIE CAT sold!") +
  theme_avatar(title.size = 24,
               subtitle.size = 20,
               text.font = "Titillium Web", 
               text.size = 20,
               legend.position = "none")

You can mix-and-match with other themes in the package, other packages, or your own custom ones. It should fit seamlessly into your ggplot2 workflow!

ggplot(diamonds, aes(price, fill = cut)) +
  geom_histogram(binwidth = 500) +
  scale_fill_stevenUniverse(palette = "CrystalGems") +
  labs(title = stringr::str_wrap("We... Are The Crystal Gems! We'll Always Save The Day! And If You Think We Can't, We'll Always Find A Way!", width = 70),
       subtitle = stringr::str_wrap("That's Why The People Of This World... Believe In: Garnet, Amethyst... Aaand Pearl!", width = 70),
       caption = "... AND STEVEN!") +
  theme_spongeBob(title.size = 24,
                  subtitle.size = 20,
                  text.font = "Titillium Web",
                  text.size = 18,
                  legend.position = "none")

What’s been surprising for me since making this package is how many people use it for educational purposes in their classrooms/workshops. It was originally just for fun and a way to practice creating a simple R package but I can see how it can be a fun educational tool for learning about ggplot2 colors and theme-ing, so thank you to all the users!

As always feel free to suggest new themes/palettes for TV shows via Twitter or by commenting on the main Github issue!

To leave a comment for the author, please follow the link and comment on their blog: R by R(yo).

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)