Themes {.build}

You can change almost everything you see on your chart, but a lot of the things you may look to change are part of the "theme"

Here we are going to change some features about our title text:

ggplot(r dataframe_name, aes(x=r df_char1_name, y=r df_numeric1_name) +
geom_jitter() +
geom_boxplot(aes(color =r df_char1_name)) +
labs(title = "My first plot") +
theme(plot.title = element_text(face = "bold", size = 12))

Themes {.build}

theme1 <- ggplot(df_input, aes(!!sym(df_char1_name), !!sym(df_numeric1_name))) +
  geom_jitter() +
  geom_boxplot(aes(color = !!sym(df_char1_name))) +
  labs(title = "My first plot") +
  theme(plot.title = element_text(face = "bold", size = 12)) 
original_plot + theme1

Themes {.build}

Next, let's change the aesthetics of our legend box

ggplot(r dataframe_name, aes(x=r df_char1_name, y=r df_numeric1_name) +
geom_jitter() +
geom_boxplot(aes(color =r df_char1_name)) +
labs(title = "My first plot") +
theme(plot.title = element_text(face = "bold", size = 12),
legend.background = element_rect(fill="gray", colour="black"))

Themes {.build}

theme2 <- ggplot(df_input, aes(!!sym(df_char1_name), !!sym(df_numeric1_name))) +
  geom_jitter() +
  geom_boxplot(aes(color = !!sym(df_char1_name))) +
  labs(title = "My first plot") +
  theme(plot.title = element_text(face = "bold", size = 12), 
        legend.background = element_rect(fill="gray", colour="black")
  ) 
theme1 + theme2

Themes {.build}

Finally, let's change the legend position

ggplot(r dataframe_name, aes(x=r df_char1_name, y=r df_numeric1_name) +
geom_jitter() +
geom_boxplot(aes(color =r df_char1_name)) +
labs(title = "My first plot") +
theme(plot.title = element_text(face = "bold", size = 12),
legend.background = element_rect(fill="gray", colour="black"),
legend.position = "bottom"))

Themes {.build}

theme3 <- ggplot(df_input, aes(!!sym(df_char1_name), !!sym(df_numeric1_name))) +
  geom_jitter() +
  geom_boxplot(aes(color = !!sym(df_char1_name))) +
  labs(title = "My first plot") +
  theme(plot.title = element_text(face = "bold", size = 12), 
        legend.background = element_rect(fill="gray", colour="black"),
        legend.position = "bottom"
  ) 
theme2 + theme3

Themes {.build}

Pre-set themes also exist as an easy way to change the entire theme of your graph quickly. They can also be combined with custom theme settings

ggplot(r dataframe_name, aes(x=r df_char1_name, y=r df_numeric1_name) +
geom_jitter() +
geom_boxplot(aes(color =r df_char1_name)) +
labs(title = "My first plot") +
theme_minimal()

Themes {.build}

theme4 <- ggplot(df_input, aes(!!sym(df_char1_name), !!sym(df_numeric1_name))) +
  geom_jitter() +
  geom_boxplot(aes(color = !!sym(df_char1_name))) +
  labs(title = "My first plot") +
  theme_minimal()
theme1 + theme4


matthewhirschey/bespokelearnr documentation built on Oct. 11, 2020, 12:57 a.m.