Created
April 19, 2020 05:24
-
-
Save shabbychef/0ffefa6f1093e29715688d8fe2b3f4d3 to your computer and use it in GitHub Desktop.
negroni plot
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(dplyr) | |
library(ggplot2) | |
library(ggpattern) | |
library(cocktailApp) | |
data(cocktails) | |
# geometry of the tumblers | |
botwid <- 0.8 | |
topwid <- 1.0 | |
height <- 0.9 | |
dwid <- topwid - botwid | |
cocktails %>% | |
dplyr::filter(grepl('^Negroni',cocktail),grepl('diffords',url),unit=='fl oz') %>% | |
filter(!grepl('4083',url)) %>% # 'Negroni Bianco' is doubled. ugh. | |
arrange(cocktail,desc(proportion)) %>% | |
group_by(cocktail) %>% | |
mutate(topy=cumsum(proportion) / sum(proportion)) %>% | |
mutate(boty=dplyr::lag(topy,1,0)) %>% | |
mutate(botdel=botwid + boty * dwid,topdel=botwid + topy * dwid) %>% | |
mutate(x_a=-botdel/2,x_b=botdel/2,x_c=topdel/2,x_d=-topdel/2, | |
y_a=boty,y_b=boty,y_c=topy,y_d=topy) %>% | |
ungroup() %>% | |
tidyr::gather(key=series,value=value,matches('^[xy]_[abcd]$')) %>% | |
select(ingredient,cocktail,proportion,series,value) %>% | |
tidyr::separate(series,into=c('xy','order'),'_') %>% | |
arrange(order) %>% | |
tidyr::spread(key=xy,value=value) %>% | |
mutate(y=y*height) %>% | |
ggplot(aes(x=x,y=y)) + | |
geom_polygon_pattern(aes(pattern=ingredient,fill=ingredient,pattern_fill=ingredient, | |
pattern_angle=ingredient,pattern_spacing=ingredient), | |
fill = 'white', | |
colour = 'black', | |
pattern_fill = 'black', | |
pattern_colour = 'black', | |
pattern_density = 0.35, | |
pattern_key_scale_factor = 1.3) + | |
facet_wrap(~cocktail) + | |
coord_fixed() + | |
theme_void() + | |
labs(title='Negronis') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment