0

I've had an issue as old as time when creating donut/pie charts in R (yes, I know...). The problem is that when using coord_polar(), white space is is created on the top and bottom of charts. Since I don't fully understand why this is the case I've been trying to remedy it with theme() attributes to avail. Ultimately I'm looking for the ability of my plots to have this current whitespace be customizable to my choosing.

Here is a reproducible example that produces the following plot:

set.seed(42069)
data.frame("x" = sample(letters[1:5], 800, replace = T)) %>% 
  count(x) %>% 
  mutate("total" = sum(n),
         "percent" = n/total) %>% 
  
  ggplot(aes(x = 2, y = percent, fill = x))+
  coord_polar(theta = "y", start = 0)+
  geom_bar(stat = "identity")

Image

Hard to see, but there is a white background on the top and the bottom (hence the spacing from the image seen in this chunk of text).

Connor
  • 39
  • 5
  • 4
    It probably a setting in the device. If you're using `ggsave()`, I think you could use `ggsave(..., bg = "black")` to set the device blackground to black. – teunbrand Jul 09 '20 at 17:46
  • 2
    Related? [Remove extra space and ring at the edge of a polar plot](https://stackoverflow.com/questions/20808009/remove-extra-space-and-ring-at-the-edge-of-a-polar-plot) – Henrik Jul 09 '20 at 17:50
  • @teunbrand is right. It's an artifact of the device's default background colour. Modifying the `dev.args` list changes the output! – Connor Jul 09 '20 at 18:22

0 Answers0