ggplot label code example

Example 1: change label x axis ggplot2

theme(
  axis.title = element_text(),         # Change both x and y axis titles
  
  axis.title.x = element_text(),       # Change x axis title only
  axis.title.x.top = element_text(),   # For x axis label on top axis
  
  axis.title.y = element_text(),       # Change y axis title only
  axis.title.y.right = element_text(), # For y axis label on right axis
)

Example 2: ggalluvial ggplot label

ggplot(vaccinations,
       aes(x = survey, stratum = response, alluvium = subject, y = freq,
           fill = response, label = response)) +
  scale_x_discrete(expand = c(.1, 0)) +
  geom_flow(width = 1/4) +
  geom_stratum(alpha = .5, width = 1/4) +
  ggfittext::geom_fit_text(stat = "stratum", width = 1/4, min.size = 3) +
  theme(legend.position = "none") +
  ggtitle("vaccination survey responses", "labeled using `geom_fit_text()`")

Tags:

R Example