0

I'm trying to build a custom ggplot theme in R, but when I try to use the plot I get the error in the header.

The code is such:

 test <- ggplot(pop_annual_12000, mapping=aes(x=year, y=WorldPop)) + geom_smooth() + light_theme()

Here's the code used to build the theme:

light_theme <- function(){theme(
  axis.title = element_text(family=font_add_google("Source Sans Pro"), colour = "#242e3c"),
  axis.text = element_text(family=font_add_google("Source Sans Pro"), colour = "#242e3c"),
  axis.ticks.x = element_line(colour="#e8e8e8"),
  axis.ticks.y = element_line(linetype="blank"),
  axis.line.x = element_line(linetype="blank"),
  axis.line.y = element_line(linetype="blank"),
  legend.text = element_text(family=font_add_google("Source Sans Pro")),
  panel.border = element_rect(linetype="blank"),
  panel.grid = element_rect(colour="#e8e8e8", linetype = "dashed"),
  plot.title = element_text(family=font_add_google("Playfair Display"), colour= "#242e3c"))}

Not sure what I'm doing that's causing the error.

Edit:

The non-base R packages used were RColorBrewer, sysfonts, and tidyverse. The input would just be a data frame (similar to the pre-loaded dataframes like diamond or nycflights13), and the output I'm expecting is just a ggplot that implements my theme.

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Include all non-base R package that you are using. `font_add_google` probably should not be in the `theme()` command. Are you following a guide from somewhere? – MrFlick Apr 21 '21 at 20:41
  • @MrFlick Hi there. To quickly answer the question, I'm not following a guide per se, but I am looking through the documentation for creating themes with ggplot. The packages that I'm using are tidyverse, RColorBrewer, and sysfonts. The input would just be a data frame (similar to the pre-loaded dataframes like diamond or nycflights13), and the output I'm expecting is just a ggplot graph that implements my theme. I'll update my answers with this information as well. – Pantagruels Pendulum Apr 21 '21 at 20:56

0 Answers0