Created
December 30, 2018 06:57
-
-
Save chichacha/2765baff8042b43eb90292e43c362b46 to your computer and use it in GitHub Desktop.
Playing Around with Chernoff Face (aplpack 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(aplpack) | |
draw_faces <- function(x=c(0,1,2,3,4,5),size=25, ncolors=10){ | |
df <- tibble( | |
face_h = sample(x, size=size, replace=T), | |
face_w = sample(x, size=size, replace=T), | |
face_s = sample(x, size=size, replace=T), | |
mouth_h = sample(x, size=size, replace=T), | |
mouth_w = sample(x, size=size, replace=T), | |
smile = sample(x, size=size, replace=T), | |
eye_h = sample(x, size=size, replace=T), | |
eye_w = sample(x, size=size, replace=T), | |
hair_h = sample(x, size=size, replace=T), | |
hair_w = sample(x, size=size, replace=T), | |
hair_s = sample(x, size=size, replace=T), | |
nose_h = sample(x, size=size, replace=T), | |
nose_w = sample(x, size=size, replace=T), | |
ear_w = sample(x, size=size, replace=T), | |
ear_h = sample(x, size=size, replace=T) | |
) %>% unite(col="val",sep="",remove=F) | |
skincolour <- sample(c("#fee1b9", "#fdc786", "#bf9765", "#fbc54A", "#fbc5A4", "#aa6948", "#fdeec7", "#fbd39b", "#c8b17b", "#fcbd84", "#f98c44", "#9a572A", "#a87256", "#6f331d", "#9f7c56", "#633c1d", "#190f07", "#b89c84", "#855f44", "#34251b"),replace=T,size=ncolors) | |
eyecolour <- sample(c("#798E2F", "#556020", "#A18836", "#58381D", "#3D2114", "#26170D", "#454317", "#398E2F", "#2B6582", "#2D7186", "#2F818E", "#0B1322", "#1E1F0A", "#130A06","#634e34","#2e536f","#3d671d","#1c7847","#497665"),replace=T,size=ncolors) | |
lipcolour <- sample(c("#eec1ad","#dbac98","#d29985","#c98276","#e35d6a"),replace=T, size=ncolors) | |
haircolour <- sample(c("#221F0B", "#3D2714", "#6B4B24", "#C6B653", "#0F0B05", "#3D3114", "#ECE8C6", "#1F1B0A", "#040301", "#0A0B04","#1f83b4", "#12a2a8", "#bcbd22", "#ffbf50", "#ff7f0e", "#c7519c", "#ba43b4", "#6f63bb"),replace=T,size=ncolors) | |
faces(df %>% select(-val), face.type=1, | |
ncolors=ncolors, | |
col.face = skincolour, | |
col.hair = haircolour, | |
col.lips = lipcolour, | |
col.ears = skincolour, | |
col.nose = skincolour, | |
col.eyes = eyecolour, | |
labels=df$val, print.info=F, cex=1) | |
} | |
draw_faces(x=seq(0,9,by=1),size=64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment