Skip to content

Polygon segments with coord_polar() near 0 #5023

Closed
@Darxor

Description

@Darxor

In some (undeniably edge, but still real) cases current version of ggplot2 draws polygons near 0 with too few segments. Short example is this:

library(ggplot2)

df <- data.frame(
  x = 1:3,
  y = c(2, 4, 20)
)

ggplot(df, aes(x, y, fill = factor(y))) +
  geom_col(width = 1, show.legend = FALSE) +
  scale_y_continuous(limits = c(0, 50)) +
  coord_polar() +
  theme_void()

Which leads to a plot like this (heavily zoomed in), where you can see red bar only has two outer segments and looks like a diamond, rather than a segment of a circle.
lowpoly

This becomes more obvious, when displaying plots in high real-world resolution - on a big screen, projector, etc., because it doesn't depend on a graphics device.

I've found out (from a stackoverflow post discussing this very same issue) that changing the default value of segment_length in coord_munch() from 0.01 to 0.002 improves quality (see image below), and doesn't seem to degrade performance too much (in my not-very-thorough benchmarks it was down 0-4%).
highpoly

Given that, my proposal is to change the default value of segment_length to something smaller.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions