thomasp85 / ggforce

Accelerating ggplot2
https://ggforce.data-imaginist.com
Other
916 stars 105 forks source link

Does StatDelaunayTile inherit aesthetics differently than StatVoronoiTile? #293

Closed tjebo closed 7 months ago

tjebo commented 1 year ago

The issue was reported by user Myriad on stack overflow. https://stackoverflow.com/questions/74922058/colour-fill-delaunay-plot-similar-to-this-voronoi-plot-in-r

It seems as if StatDelaunayTile doesn't inherit aesthetics in the same way as StatVoronoiTile and I am not sure if this is desired?

On using browser within the respective compute_group functions, it becomes evident that the data created in StatDelaunayTile$compute_group doesn't contain fill or PANEL column in the below example - whereas the data created with StatVoronoiTile$compute_group has those columns. The warning given seems to indicate that the aesthetic might not be correctly recognised?

library(ggforce)
#> Loading required package: ggplot2

ggplot(iris, aes(Sepal.Length, Sepal.Width, fill = Petal.Length)) +
  geom_voronoi_tile()
#> Warning: `stat_voronoi_tile()` is dropping duplicated points


ggplot(iris, aes(Sepal.Length, Sepal.Width, fill = Petal.Length)) +
  geom_delaunay_tile()
#> Warning: `stat_delaunay_tile()` is dropping duplicated points
#> Warning: The following aesthetics were dropped during statistical transformation: fill
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#>   the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#>   variable into a factor?

Created on 2022-12-26 with reprex v2.0.2

thomasp85 commented 7 months ago

It is different, but for good reason. The tile in the triangulation is related to three points, not one, so there is no way to match the fill value to the final tile and thus these values are dropped. This is not an issue with the voronoi tessellation because each til is related to a single point.