Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill delaunay triangles with colors of vertex points in R #292

Open
hcuve opened this issue Dec 25, 2022 · 1 comment
Open

fill delaunay triangles with colors of vertex points in R #292

hcuve opened this issue Dec 25, 2022 · 1 comment
Labels
feature a feature request or enhancement

Comments

@hcuve
Copy link

hcuve commented Dec 25, 2022

First off, thank you so much for contributing such amazing resources like this.

I am trying to fill the Delaunay triangles using the colors of the edge points.
here is a reprex

data<- structure(list(lanmark_id = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 
59, 60, 61, 62, 63, 64, 65, 66, 67), V1 = c(0.00291280916742007, 
0.00738863171211713, 0.0226678081211574, 0.0475105228945172, 
0.0932285720818941, 0.167467706279089, 0.257162845610094, 0.365202733889021, 
0.49347857580521, 0.623654594804239, 0.738846221030799, 0.838001377618909, 
0.911583795022151, 0.954620025430512, 0.976736039833402, 0.99275439380643, 
1.00100526672829, 0.0751484964183746, 0.136267471453466, 0.223219796351563, 
0.312829176190895, 0.396253287447153, 0.589077347394549, 0.682150866526948, 
0.771279538477539, 0.856242644022999, 0.915433541338973, 0.493665602840245, 
0.491283285973581, 0.488913167946858, 0.486968906096063, 0.384707082576335, 
0.43516446651127, 0.48730704698643, 0.541730425616146, 0.590794609520034, 
0.176234316360877, 0.230353437655898, 0.295908510434122, 0.350673723300921, 
0.2927721757992, 0.228392965512228, 0.634474821310078, 0.692554938010577, 
0.757884656518485, 0.809961553290539, 0.760324208523177, 0.696892501347341, 
0.299062528225204, 0.371899560139738, 0.440183530232855, 0.488448817156316, 
0.542120710507391, 0.613931454931259, 0.683122622479693, 0.614367295821043, 
0.544516611213321, 0.487065702940653, 0.43466839036949, 0.367662837035504, 
0.329392110306872, 0.439192556373207, 0.488617118648197, 0.543288506065858, 
0.652131615571443, 0.541622182786469, 0.486664920417254, 0.437126878794749
), V2 = c(0.201088019764115, 0.335422141956174, 0.468591127485112, 
0.597955245417373, 0.719502795031081, 0.826191980419368, 0.912263437847338, 
0.978932088608654, 0.996572250349122, 0.975164350943783, 0.906204543800476, 
0.817791059656974, 0.711167374856116, 0.587462637963028, 0.457981280500493, 
0.327526817895531, 0.19652402489511, 0.0832018969548692, 0.0247526745448235, 
0.00543973063471442, 0.0169853862992864, 0.0463565705952832, 
0.0442986445765913, 0.0151651597693172, 0.00747493463745755, 
0.0263496825405166, 0.0805712600069456, 0.160307477500307, 0.24640401358039, 
0.332244740019727, 0.420995916418539, 0.486383354389177, 0.505514985155285, 
0.521022030162301, 0.5059272511442, 0.48818970795347, 0.184054088286897, 
0.153658218058329, 0.153359749238857, 0.186997311695192, 0.20294291755153, 
0.204166125257439, 0.186997311695192, 0.153386090373069, 0.155932705636629, 
0.184603717976376, 0.203900583330345, 0.202836636618411, 0.670663080116174, 
0.635972857244521, 0.619932598923225, 0.632625553953685, 0.620132318139554, 
0.637530241507316, 0.668109937001625, 0.718821664744205, 0.73956412947459, 
0.744898219300658, 0.74046882628352, 0.720755964662638, 0.672731384920681, 
0.666152981987244, 0.670464844757437, 0.664772611108765, 0.671145517468628, 
0.673968618595099, 0.67986363963374, 0.675352028351748), coef2 = c(0, 
0, 0, 0, 0, 0, 0, 0, 0.565178003460693, 0, 0, 0, 0, 0, 0, 0, 
0, 0.0433232019717308, 0.0433232019717308, 0.442833876807268, 
0.574211955093656, 0.574211955093656, 0.574211955093656, 0.574211955093656, 
0.442833876807268, 0.0433232019717308, 0.0433232019717308, 0.0612451242746323, 
0.0612451242746323, 0, 0, 0, 0, 0, 0, 0, 0.343056259557492, 0.701076795777046, 
0.674029769391816, 0, 0.538117834886036, 0.990039002564078, 0.451921167678043, 
0.701076795777046, 0.701076795777046, 0.316009233172263, 0.990039002564078, 
0.990039002564078, 0.878350036859346, 0.343364662128988, 0.282119537854356, 
0.282119537854356, 0.282119537854356, 0.343364662128988, 0.384793696241895, 
0.608382647917744, 0.608382647917744, 1, 0.608382647917744, 0.608382647917744, 
0.384793696241895, 0.501936678206125, 0.501936678206125, 0, 0.878350036859346, 
0, 0.501936678206125, 0.501936678206125)), row.names = c(NA, 
-68L), class = c("tbl_df", "tbl", "data.frame"))

I used this data to create a deulanay plot in R

library(tidyverse)
library(ggforce)

data%>%
  mutate(coef2 = coef2/max(coef2))%>%
  ggplot(aes(V1, V2))+
  geom_delaunay_tile(aes(colour = coef2, fill = coef2), alpha = .5)+
  geom_delaunay_segment2(aes(colour = coef2, fill = coef2))+
    geom_point(aes(colour = coef2))+
  ylim(1,0)+
  scale_color_viridis_c(option = "magma")+
 scale_fill_viridis_c(option = "magma")+
theme_minimal()

which gives
image

I want to fill all triangles with a blend of colors that match the color of each point, just as the lines are colored.

as you can see I have tried using fill = coef2 within de geom_delaunay but this doesn't really achieve what I want.

is there a work around to do this with ggforce

Many thanks!

for transparency, I first posted this on StackOverflow a couple of weeks ago but still haven't managed to work out a solution

@thomasp85 thomasp85 added the feature a feature request or enhancement label Jan 18, 2024
@thomasp85
Copy link
Owner

This is unfortunately not possible right now andI can't see if/when it will be possible for technical reasons. I'll leave it open as a reminder but don't expect much action on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants