'In ggplot2, how to add a white hole in the middle of the pie chart

In ggplot2, how to add a white hole in the middle of the pie chart? Please refer to below code for current plot (the left plot) . Thanks!

library(tidyverse)
pie_data <- data.frame(category=c('A','B','C','A','B','C'),
                       year=c(2020,2020,2020,2021,2021,2021),
                       sales=c(40,30,20,10,15,10))




pie_data %>% ggplot(aes(x=factor(year),y=sales,fill=category))+
  geom_col(position='fill',width=1,color='white')+
 coord_polar(theta = 'y')+
  theme_void()

enter image description here



Solution 1:[1]

You can add an hollow bar at the center:

  pie_data %>% ggplot(aes(x=factor(year),y=sales,fill=category))+
      geom_col(position='fill',width=1,color='white')+
      coord_polar(theta = 'y')+
      geom_col(aes(x=0,y=0))+
      theme_void()

enter image description here

if you want a larger circle, use a negative x coordinate:

geom_col(aes(x=-1,y=0))

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1