tidyverse / ggplot2

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

Feature request: radar/spider coordinate system #5950

Open dafxy opened 2 weeks ago

dafxy commented 2 weeks ago

See https://github.com/tidyverse/ggplot2/issues/5913. It should be reopened.

teunbrand commented 2 weeks ago

Repeating from previous discussion: 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

From previous discussion: 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.

thomasp85 commented 2 weeks ago

What I believe @dafxy is after is a spider/radar plot option, which, true, isn't possible currently

I personally only think such a thing makes sense for a discrete scale so I don't know if this should be a new coordinate system altogether or something (wrongly) tacked on to coord_radial()

dafxy commented 2 weeks ago

Yes!

teunbrand commented 2 weeks ago

Thanks Thomas, that makes the intent more clear because that is a somewhat different coordinate system than the polar ones. @dafxy I think you might be looking for coord_radar() offered by {see}.

library(ggplot2)

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

Created on 2024-06-20 with reprex v2.1.0

I'm not sure if this is worth carrying over to ggplot2, as it already exists in extension packages.

thomasp85 commented 2 weeks ago

An argument for bringing it over would be to give it the same treatment as coord_polar() got with coord_radial(), i.e. support for the new axes

teunbrand commented 2 weeks ago

One particular nuance is that coord_polar() (on which see::coord_radar() is based) sort-of hardcodes decorations (panels, grid, axes), whereas coord_radial() munches these decorations. Simply setting the is_linear() method to TRUE, as see::coord_radar() does, will mistransform the decorations in coord_radial().

thomasp85 commented 2 weeks ago

yes, we obviously need a better approach if we should do it... For now see is the way

teunbrand commented 2 weeks ago

An additional concern will be how to treat polygons spanning start/end boundaries.

image

teunbrand commented 1 week ago

I'm going to consider this a feature request for a spider/radar coord instead of a report on the lack of options.