Created
March 15, 2020 23:55
-
-
Save chichacha/63f9428e89d71fffa624f8df6000af0e to your computer and use it in GitHub Desktop.
Using chull to select points from group to draw smooth curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ggforce) | |
## Generate Random Points | |
controls <- data.frame( | |
x = runif(n=100), | |
y = rbeta(n=100,shape1=0.8,shape2=0.7) | |
) %>% mutate(grp=rep(c(1:10),each=10)) %>% | |
mutate(x=x+grp)%>% | |
group_by(grp) %>% | |
ungroup() | |
controls2<-controls %>% | |
group_by(grp) %>% | |
nest() %>% | |
mutate(hull=map(data, ~chull(.)), | |
out=map2(data,hull,~.x[.y,,drop=F])) %>% | |
unnest(out) | |
controls %>% | |
ggplot(aes(x=x,y=y,group=grp, color=factor(grp))) + | |
geom_point(size=2) + | |
geom_bspline_closed(fill="#00000030", color="#ffffff00") + | |
coord_fixed() + | |
theme_void() + | |
geom_bspline_closed(data=controls2 %>% mutate(y=y-2), fill="#23232350", color="#ffffff00") + | |
geom_point(data=controls2 %>% mutate(y=y-2), shape=19, size=3) + | |
geom_point(aes(y=y-2), alpha=0.8, size=2, shape=21)+ | |
scale_color_tableau(guide="none") + | |
annotate(geom="text",x=0,y=1.2,label="Sets of Random Points + B-Spline", hjust=0, family="Roboto Condensed") + | |
annotate(geom="text", x=0, y=-0.8, label="Sets of Random Points with Selected Subset using chull to create smooth shape", hjust=0, family="Roboto Condensed") | |
Author
chichacha
commented
Mar 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment