Created
August 11, 2019 21:51
-
-
Save chichacha/70a1ea865689bd316ed27ac00ff0f9bd to your computer and use it in GitHub Desktop.
Experimentation with ggforce Package
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(tidytext) | |
library(ggforce) | |
library(patchwork) | |
library(ggthemes) | |
## prep colour palettes | |
hue_circle <- ggthemes::tableau_color_pal("Hue Circle")(16) | |
## funciton to create art | |
create_art <- function(name="type anything", my_col = hue_circle) { | |
my_col <- my_col | |
lucky_color = sample(my_col,size=1) | |
point_color = sample(my_col, size=1) | |
## Create a lookup table | |
df <- tibble( | |
letter = c(letters,NA), | |
theta = seq(0,2*pi, length.out=27) | |
) %>% mutate(x=cos(theta), y=sin(theta)) | |
## convert strings into data frame | |
name_df <-tibble(name=name) %>% | |
tidytext::unnest_tokens(output=letter,input=name, token="characters") %>% | |
mutate(letter=letter) %>% | |
add_count(letter,name="size") %>% | |
left_join(df, by="letter") | |
## get basic shapes from alphabet being used in names | |
name_df %>% select(x,y) %>% chull() -> my_seq | |
## duplicate will be removed | |
name_df_hull <- name_df[my_seq,] | |
art <-name_df %>% | |
ggplot(aes(x=x,y=y)) + | |
geom_bspline_closed(fill=lucky_color, alpha=0.6) + | |
geom_bspline_closed(data=name_df_hull, fill=lucky_color, alpha=0.4) + | |
geom_path(size=0.1, color="#ffffffde") + | |
geom_point(aes(size=size), color=point_color, alpha=0.7)+ | |
geom_text(aes(label=str_to_upper(letter)), | |
family="Roboto Condensed", color="#ffffffde") + | |
coord_fixed() + | |
theme_void() + | |
scale_size_continuous(range=c(5,8), guide="none") + | |
annotate(geom="text", x=0,y=0, size=8, family="Roboto Condensed", | |
label=str_to_title(name), color="#000000de") | |
print(art) | |
} | |
create_art() | |
create_art("jelly beans") + | |
create_art("chupa chups ") + | |
create_art("gummy bears") + | |
create_art("apple pie") + | |
create_art("chocolate cake") + | |
create_art("tootsie roll") + | |
create_art("tiramisu") + | |
create_art("cotton candy") + | |
create_art("lemon drops") + | |
create_art("bear claw") + | |
create_art("beaver tail") + | |
create_art("gingerbread cookie") | |
ggsave("~/Downloads/Organic_Shape_Experiment_sweets.png", width=16, height=12) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's example of art created :)