Created
December 19, 2021 20:05
-
-
Save MattSandy/70d7a854a648565300bca3ab42c04c08 to your computer and use it in GitHub Desktop.
Christmas Tree in R
This file contains hidden or 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) | |
df <- data.frame( | |
x1 = rep(0,200), | |
y1 = 21:220 + sample(1:10,200,replace = TRUE), | |
g = 1:200 | |
) %>% | |
cbind( | |
data.frame( | |
x2 = (200:1 + (sample(1:200,200,replace = TRUE)/100)) / 1.5, | |
y2 = 1:200 - log(1:20) - (sample(1:200,200,replace = TRUE)/100) | |
) | |
) %>% | |
rbind( | |
.[,] %>% | |
mutate( | |
x2 = x2 * -1, | |
g = max(.$g) + 1:nrow(.) | |
) | |
) %>% | |
group_by(g) %>% | |
mutate( | |
bulb = ifelse(g%%7==0,sample(-abs(x2):abs(x2),1),NA) | |
) | |
df %>% | |
ggplot( | |
aes( | |
x = bulb, | |
y = y2, | |
group = g, | |
color = as.factor(y2) | |
) | |
) + | |
geom_curve( | |
aes( | |
x = x1, | |
y = y1, | |
xend = x2, | |
yend = y2, | |
), | |
color = "#009900", | |
curvature = -0.2 | |
) + | |
geom_curve( | |
aes( | |
x = x1, | |
y = y1, | |
xend = x2, | |
yend = y2, | |
), | |
color = "#009900", | |
curvature = 0.2 | |
) + | |
geom_point(size = 4) + | |
ggmap::theme_nothing() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment