'How to make a pie() chart larger in R without it cutting off?

I am currently trying to make a pie chart with the pie() function in base R. How can I make it bigger? I have tried radius = 1.2, but this ends up cutting the chart off at the top and bottom (see attached image). How can I make it so that it is larger and not cut off? Here is my code:

explicitProp <- c(as.numeric(summary(ts$explicit)[[2]]), 
                  as.numeric(summary(ts$explicit)[[3]]))

pie(explicitProp, 
    labels = c("93.95%", "6.04%"),
    col = c("#bc5090", "#003f5c"),
    main = "Explicit vs. Clean Songs in Taylor Swift's Discography",
    radius = 1
    )
legend("topright", c("Clean", "Explicit"), fill = c("#bc5090", "#003f5c"))

Also, I know pie charts are typically frowned upon. However, when comparing two outcomes, it seems like a better alternative to a bar chart. Is there another form of visualization I am missing out on that might better serve my goals? Pie Chart Cut Off w/Radius > 1



Solution 1:[1]

The pie() function in base graphics is a bare bones plot. The manual page actually recommends that you not use it: "Pie charts are a very bad way of displaying information." The standard radius for the pie chart is based on the the available space in the plot. If your plot window is wider across than vertically, the radius will adjust to the vertical space minus the default margins. The default margins are c(5.1, 4.1, 4.1, 2.1) lines on bottom, left, top, right to allow space for titles and axes labels. Here are some examples to make things clearer.

par(mfrow=c(2, 2))   # Divide plot into 4 quarters
pie(c(7, 83, 33, 37, 14))  # Upper left, default plot, radius=0.8
pie(c(7, 83, 33, 37, 14), radius=1.05)  # Upper right, slightly larger
par(mar=c(0, 0, 0, 0))     # Remove default margins
pie(c(7, 83, 33, 37, 14))  # Same plot as upper left, but no margins
pie(c(7, 83, 33, 37, 14), radius=1.05)  # Same plot as upper right without margins

enter image description here

Notice that some of the labels are truncated in the bottom right pid chart.

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