tidyverse / ggplot2

An implementation of the Grammar of Graphics in R

Home Page:https://ggplot2.tidyverse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could polygons be drawn, so that the outline does Not exceed the value it represents?

davidhodge931 opened this issue · comments

I think it'd be an improvement if polygons were drawn, so that the outline does not exceed the value that it represents.

This would:

  1. visually represent the data most accurately
  2. enable polygons to be positioned next to each other without outlines ever over-lapping

Maybe there are some circumstances I could imagine where the previous behaviour is what is wanted by the user, so maybe they could revert to this behaviour if desired (e.g. outline_position = c("inside", "centre")).

But I think it should default to representing the data in the most visually accurate way as described above.

Example below in an exaggerated way to demonstrate what I'm talking about

library(tidyverse, quietly = TRUE)
#> Warning: package 'ggplot2' was built under R version 4.4.1
library(palmerpenguins, quietly = TRUE)

tibble(x = letters[1:3], y = 1:3) |>
  ggplot(aes(x = 1, y = y, colour = x)) +
  geom_col(position = "dodge", linewidth = 10, fill = NA) +
  geom_hline(yintercept = 1:3) +
  geom_vline(xintercept = seq(0.55, 1.45, (1.45-0.55)/3))

Created on 2024-07-12 with reprex v2.1.0

While I understand where you are coming from, this runs counter to how all graphics software works. Further, while certainly doable, it would destroy performance and rely on features not available in all graphics devices so such a feature is better suited for a specialised geom in an extension

I agree with Thomas. If {grid} ever implements this as a graphical parameter, I'd be happy to reconsider but I can't see an efficient homebrew solution to this problem. For axis-aligned rectangles, you might get away with adding/subtracting a linewidth from the width and height, but that'd translate poorly in non-linear coord systems.

Ah, yeah thought this might be complicated, as I've never seen it implemented before.

Thanks for the explanations

If either of you are interested in investigating this in {ggforce} or {gghx}, let me know and I'll raise the issue there.

It'd be a nice feature, even if it only worked for bar graphs with linear scales