thomasp85 / ggforce

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

`geom_mark_hull` doesn't work anymore with two points #299

Closed jantusan closed 9 months ago

jantusan commented 1 year ago

Hello,

I am unable to plot hulls surrounding two dots using geom_mark_hull(). it used to work until I updated the tidyverse and ggforce to the latest versions.

Here is some example data:

library(tidyverse)
library(ggforce)

test_dataset <- tibble(x     = c(-235, -220,  187, -100, -162,   8, 336, 159, 443, -77, -412), 
                       y     = c( -32, -147, -123,    6,  102, -14,  40,   6,  15, 115,   30),
                       group = c( "a",  "a",  "a",  "b",  "b", "b", "c", "c", "c", "d",  "d"))

When using geom_ellipse() it works good (one of the reasons I started using geom_mark_hull() was that it was faliling to draw ellipses surrounding two points, but this is fixed now as described in #214)

ggplot(test_dataset, aes(x = x, y = y, fill = group)) + 
  geom_mark_ellipse() +
  geom_point(shape = 21, size = 3, color = "black")

image

But for geom_mark_hull() it doesn't even draw any shape for the group with two point, even though it used to work before:

ggplot(test_dataset, aes(x = x, y = y, fill = group)) + 
  geom_mark_hull() +
  geom_point(shape = 21, size = 3, color = "black")

image

This is my sessionInfo()

R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Ventura 13.2.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggforce_0.4.1   lubridate_1.9.2 forcats_1.0.0   stringr_1.5.0   dplyr_1.1.0     purrr_1.0.1     readr_2.1.4     tidyr_1.3.0     tibble_3.1.8   
[10] ggplot2_3.4.1   tidyverse_2.0.0 devtools_2.4.5  usethis_2.1.6  

loaded via a namespace (and not attached):
 [1] pkgload_1.3.2     jsonlite_1.8.4    carData_3.0-5     shiny_1.7.4       remotes_2.4.2     sessioninfo_1.2.2 pillar_1.8.1      backports_1.4.1  
 [9] glue_1.6.2        digest_0.6.31     promises_1.2.0.1  ggsignif_0.6.4    polyclip_1.10-4   colorspace_2.1-0  htmltools_0.5.4   httpuv_1.6.9     
[17] pkgconfig_2.0.3   broom_1.0.3       xtable_1.8-4      scales_1.2.1      processx_3.8.0    tweenr_2.0.2      later_1.3.0       tzdb_0.3.0       
[25] timechange_0.2.0  generics_0.1.3    farver_2.1.1      car_3.1-1         ellipsis_0.3.2    ggpubr_0.6.0      cachem_1.0.7      withr_2.5.0      
[33] cli_3.6.0         magrittr_2.0.3    crayon_1.5.2      mime_0.12         memoise_2.0.1     ps_1.7.2          fs_1.6.1          fansi_1.0.4      
[41] MASS_7.3-58.2     rstatix_0.7.2     pkgbuild_1.4.0    profvis_0.3.7     tools_4.2.2       prettyunits_1.1.1 hms_1.1.2         lifecycle_1.0.3  
[49] V8_4.2.2          munsell_0.5.0     callr_3.7.3       compiler_4.2.2    concaveman_1.1.0  rlang_1.0.6       grid_4.2.2        rstudioapi_0.14  
[57] htmlwidgets_1.6.1 miniUI_0.1.1.1    labeling_0.4.2    gtable_0.3.1      abind_1.4-5       curl_5.0.0        R6_2.5.1          knitr_1.42       
[65] fastmap_1.1.1     utf8_1.2.3        stringi_1.7.12    Rcpp_1.0.10       vctrs_0.5.2       tidyselect_1.2.0  xfun_0.37         urlchecker_1.0.1 
TiagoMonteiroHenriques commented 1 year ago

I've also noticed that this problem is dependent on the way the groupings are given to the function: if the first group is composed of only one or two elements, the function plots the hulls of all groups with a maximum of two elements, and fails to plot the hulls of bigger groups. If the first group is composed of more than two elements, the function plots the hulls of all groups with more than two elements, but fails to plot the hulls of smaller groups.

JiaruiTang commented 1 year ago

Got the same issue today.

road2you commented 10 months ago

temporary bypass method... https://github.com/thomasp85/ggforce/pull/312#issuecomment-1859660060