tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.39k stars 2k forks source link

coord_radial() and coord_polar() are not connecting the start and end points anymore (v3.5.1) #5913

Closed dafxy closed 1 month ago

dafxy commented 1 month ago

This was working in older ggplot versions, but now it is not working anymore on version 3.5.1. The racial coordinate should connect the ending and starting points. Using polar coordinates instead of radial also does not work.

set.seed(10)
df = data.frame(x = 1:10,
                y = runif(10),
                g = sample(c('A', 'B'))
                )
g = (
    df
    %>% ggplot(.)
    + geom_polygon(aes(x=x, y=y, color=g, fill=g), alpha=.5)
    + coord_radial()
)
g

Screenshot from 2024-05-28 13-18-29


g = (
    df
    %>% ggplot(.)
    + geom_polygon(aes(x=x, y=y, color=g), alpha=.5, fill=NA)
    + coord_radial()
)
g

Screenshot from 2024-05-28 13-18-48

dafxy commented 1 month ago

This is what I get with version 3.4.4:

Screenshot from 2024-05-28 13-38-24

teunbrand commented 1 month ago

Polygons are properly closed now, i.e. they are connected by a line segment that is correctly munched by the coordinate system. The previous behaviour was incorrect, which can also be shown with your example plot. You can clearly see that the 'B' shape has a self-intersection in Cartesian coordinates.

library(ggplot2)
set.seed(10)
df = data.frame(x = 1:10,
                y = runif(10),
                g = sample(c('A', 'B'))
)

p <- ggplot(df) +
  geom_polygon(aes(x=x, y=y, color=g, fill=g), alpha=.5)

p

And this self-intersection is displayed in polar coordinates.

p + coord_polar()

Created on 2024-05-29 with reprex v2.1.0

dafxy commented 1 month ago

Right, but for visualization of statiscal summaries purposes, I want to have something like in v 3.4.4, but that is completely gone, and it is breaking old code. Can you add that back, maybe witth a option in the function?

dafxy commented 2 weeks ago

Could you reopen this, please? This is not how people have used it. The one on v 3.4.4 is how many people have use it for stat visualization. See https://www.nature.com/articles/s41562-024-01908-6, for instance.

teunbrand commented 2 weeks ago

I'm afraid the article isn't accessible to me. Could you post a reproducible example of where the current behaviour is either misleading or incorrect, whereas the previous behaviour wasn't?

dafxy commented 2 weeks ago

That is in the initial measage. Whatever you had in version 3.4.4 was working just fine. This is not about mapping straight lines from Cartesian coordinates onto polar coordinates, curving the plot lines altogether with the axis. This is about having the polar coordinate to help with visualization of the points. Jus that.