Labels and Legends

Several options exist to change the default labels and legends. Recall, this code:

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))

Labels and Legends {.build}

original_plot <- ggplot(df_input, aes(!!sym(df_char1_name), !!sym(df_numeric1_name))) +
  geom_jitter() +
  geom_boxplot(aes(color = !!sym(df_char1_name)))
original_plot

But it has two problems:
1. The x-axis label is redundant
2. The figure legend is also redundant

Change labels using labs

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(x ="") #blank quotes removes the label

Change labels using labs

Gave us this plot:

ggplot(df_input, aes(!!sym(df_char1_name), !!sym(df_numeric1_name))) +
  geom_jitter() +
  geom_boxplot(aes(color = !!sym(df_char1_name))) +
  labs(x = "")

Change legend using guides

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(x ="") #blank quotes removes the label +
guides(color = "none")

Change legend using guides

lab_plot <- ggplot(df_input, aes(!!sym(df_char1_name), !!sym(df_numeric1_name))) +
  geom_jitter() +
  geom_boxplot(aes(color = !!sym(df_char1_name))) +
  labs(x = "") + 
  guides(color = "none")
original_plot + lab_plot


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