3

I'm making a piechart using ggplot2 and it looks fine in RStudio:

data <- data.frame(
  continent=c("Europe", "N. America", "S. America", "Asia", "Africa", "Australia"),
  value=c(80, 30, 20, 110, 40, 5)
)

library(ggplot2)
ggplot(data, aes(x="", y=value, fill=continent)) +
  geom_bar(stat="identity", width=1, color="black")+
  coord_polar("y") +
  theme_void() 
ggsave("piechart.png")

However, when I open the saved picture, you can see that the center has an unwanted spike from the green segment: piechart_pointy_segment

I feel this looks rather bad. Can I remove it somehow? Maybe change the line thickness so this is not as pronounced?

4
  • I am no {ggplot2} expert. Is it due to the size you use to save the plot? Have you played around around with the size arguments in ggsave? (On my machine) it defaults to > ggsave("piechart.png") Saving 8.85 x 4.46 in image. Commented Aug 28, 2024 at 8:19
  • I've tried using different sizes, and larger sizes do help a little. But it's mainly because the pointy spike seems proportionally smaller. I'd like to avoid the problem altogether, since it seems the lines are drawn longer than they need to be. Commented Aug 28, 2024 at 8:27
  • 1
    If you set the width to default 0.9, there is no issue, why are we setting it to 1? Commented Aug 28, 2024 at 8:58
  • The issue persists with width = 0.9 or omitting width Commented Aug 29, 2024 at 9:43

1 Answer 1

3

Edit

Setting the linejoin to 'bevel' helps w/o fiddling around with inner radius as in previous approach:

library(ggplot2)
ggplot(data, aes(x="", y=value, fill=continent)) +
  geom_bar(stat="identity", width=1, color="black",
           linejoin = 'bevel'
           )+
  coord_polar("y") +
  theme_void() 

no spikes with bevel linejoin

You could use coord_radial instead of coord_polar, prevent axis expansion and set a minute inner radius:


    ggplot(data, aes(x="", y=value, fill=continent)) +
      geom_bar(stat="identity", width=1, color="black")+
      coord_radial('y', expand = FALSE, inner.radius = 0.01) +
      theme_void()

spikeless pie

Sign up to request clarification or add additional context in comments.

3 Comments

You still have the green bar edge issue there.
Thank you. The inner radius needs some trial & error to maneuvre between spike and hole.
Thank you, using "bevel" works beautifully!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.