rggplot2pie-chart

R ggplot - Place title at bottom of pie chart


Been working on a pie chart in ggplot2. I have this code so far:

library(tidyverse)    
pie_tbl <- tibble(
  surface = factor(c("Dry","Wet","Snow/Ice","Other"),levels=c("Dry","Wet","Snow/Ice","Other")),
  percentage = c(78,14.8,6.9,0.2)
)


pie_tbl %>% ggplot(aes(x="",y=percentage,fill=surface)) + 
  geom_col(color='black',width=1) + coord_polar("y",start=pi/2) +
  labs(title="Surface Condition during collisions") +
  theme_void() +
  theme(plot.title = element_text(family='serif',face='bold',size=18,hjust=0.5,vjust=-1)) +
  scale_fill_manual(
    values=c(
      "Dry" = "#27B7CE",
      "Wet" = "#FB6476",
      "Snow/Ice" = "#47B972",
      "Other" = "#FEB20E"
      )
    )
)

I get this plot pieplot

vjust = -1 isn't moving the title down to the bottom. Any ideas why?

I found large negative values of vjust work (like -100), but it feels like a 'hacky' solution and there's likely a better approach.


Solution

  • One hack could be to use "caption" instead:

    labs(caption="Surface Condition during collisions") +
    theme(plot.caption = element_text(size = 16, hjust = 0.5, vjust = 2)) +
    

    enter image description here