Skip to content

rotation direction set up randomly for pie chart. #6250

Closed
@withr

Description

@withr

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)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions