Closed
Description
We are facing issues to fill the blank space in pie charts using ggplot2_3.5.1 (issue in other versions too).
The following code:
library(ggplot2)
# Create Data
data <- data.frame(
group=LETTERS[1:5],
value=c(13,7,9,21,2)
)
# Basic piechart
ggplot(data, aes(x="", y=value, fill=group)) +
geom_bar(stat="identity", width=1) +
coord_polar("y", start=0) +
theme_gray() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x = element_blank(),
)
Gives the following graph:
The issue seems to arise from the r_rescale function which has the donut = c(0, 0.4)
hardcoded. This can be fixed by overriding the function as shown below:
library(scales)
library(ggplot2)
# Create Data
data <- data.frame(
group=LETTERS[1:5],
value=c(13,7,9,21,2)
)
custom_r_rescale <- function(x, range, donut = c(0, 0.49)) {
x <- squish_infinite(x, range)
rescale(x, donut, range)
}
assignInNamespace("r_rescale", custom_r_rescale, ns="ggplot2", pos="package:ggplot2")
ggplot(data, aes(x="", y=value, fill=group)) +
geom_bar(stat="identity", width=1) +
coord_polar("y", start=0) +
theme_gray() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x = element_blank(),
)
However, this is a hacky way to solve this issue. It seems that the same issue was reported in a stackoverflow issue as well.
The question I have is if it would be possible to parametrize this parameter or this function?
Thanks a lot!
Metadata
Metadata
Assignees
Labels
No labels