Search code examples
rplotggplot2ggtern

Plotted points ternary diagram hidden under diagram


Short question: I have a ternary diagram with some points hitting the borders of the triangle. The triangle shape gets priority over the points, but I'd like it to be the other way around so the points are plotted on top of the triangle border.

Is there a quick command for this? I've googled and searched here quite extensively...

The diagram as it is now The diagram as it is now

The function I use

ggtern(data=females, aes(urban, agri,marine)) + 
  geom_point(,pch=21,col='black',bg='dodgerblue3', size= 2) + 
  geom_point(data= males, pch=21, col='black', bg= 'orange', size=2)

The data for the objects females and males respectively:

    urban       agri     marine
Eva     0.5635359 0.38121547 0.05524862
Hilde   0.7940942 0.08721014 0.11869565
Joanna  0.2413793 0.12931034 0.62931034
Karen   0.8076923 0.01442308 0.17788462
Leslie  0.9683544 0.01740506 0.01424051
Lilian  0.8000000 0.08727273 0.11272727
Louise  0.3230769 0.61025641 0.06666667
Magda   0.9765101 0.01342282 0.01006711
Mia     0.1153846 0.80769231 0.07692308
Mirte   0.0000000 0.80000000 0.20000000
Rolanda 0.3356643 0.53146853 0.13286713
Silke   0.8536585 0.14634146 0.00000000
Tatiana 0.7337662 0.00000000 0.26623377
Tessa   0.2105263 0.51127820 0.27819549
Tine    0.4070796 0.11504425 0.47787611
Veronic 0.4333333 0.07777778 0.48888889
Wilma   0.2354874 0.65724724 0.10726533

     urban       agri     marine
Ceryl   0.35775862 0.42672414 0.21551724
Claude  0.93548387 0.06451613 0.00000000
Dre     0.32638889 0.67361111 0.00000000
Francis 0.53846154 0.00000000 0.46153846
Geert   0.77777778 0.11111111 0.11111111
Hein    0.39845758 0.26992288 0.33161954
Joost   0.21495536 0.57857143 0.20647321
Jurgen  0.60482400 0.24919771 0.14597828
Koen    0.38095238 0.14285714 0.47619048
Luc     0.47241163 0.51072549 0.01686288
Maurice 0.33497665 0.03401846 0.63100489
Niels   0.70000000 0.10000000 0.20000000
Rik     1.00000000 0.00000000 0.00000000
Rudy    0.06936471 0.01224211 0.91839317
Sander  0.74242424 0.00000000 0.25757576
Suk.hyo 0.34713376 0.07961783 0.57324841
Tjess   0.41115266 0.46854652 0.12030082

Solution

  • ggtern(data=females, aes(urban, agri,marine)) + 
      geom_mask() +              # <<<<<<<<<<<<<<<< NOTE MASK UNDER POINTS LAYERS
      geom_point(,pch=21,col='black',bg='dodgerblue3', size= 2) + 
      geom_point(data= males, pch=21, col='black', bg= 'orange', size=2)