Closed
Description
I found a problem with geom_bar
I expected the brown part of the second pie chart should be on the left, but it didn't.
I found it depends on the order of color code. How to fix it?
Here is the code to reproduce the bug:
dat1 <- data.frame(year = c(2012, 2019),
value = c(1, 1),
color = c("#1CF900", "#FFA600"))
dat2 <- data.frame(year = c(2019, 2023),
value = c(1, 1),
color = c("#FFA600", "#FF4000"))
pie1 <- ggplot(dat1, aes(x = "", y = value, fill = color)) +
geom_bar(stat = "identity", width = 1) +
coord_polar(theta = "y", start = 0) +
theme_void() +
theme(legend.position = "none") +
scale_fill_identity()
pie2 <- ggplot(dat2, aes(x = "", y = value, fill = color)) +
geom_bar(stat = "identity", width = 1) +
coord_polar(theta = "y", start = 0) +
theme_void() +
theme(legend.position = "none") +
scale_fill_identity()
print(pie1 + pie2)
Metadata
Metadata
Assignees
Labels
No labels