automatically build the perfect palette for you plot …...automatically build the perfect palette...

25
automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9 th MilanoR meeting, 20 th November 2017

Upload: others

Post on 26-Apr-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

automatically build the perfect palette for you plot with paletteRAndrea Cirillo9th MilanoR meeting, 20th November 2017

Page 2: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017
Page 3: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017
Page 4: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017
Page 5: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017
Page 6: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

paletteR: palettes from custom images

• takes any image

• applies statistical learning

• builds a palette

draw from any image an optimised custom palette

Page 7: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

takes any imagex y R G B

1 275 0,9960784313725 0,9960784313725 0,9960784313725

1 274 0,9960784313725 0,9960784313725 0,9960784313725

1 273 0,9960784313725 0,9960784313725 0,9960784313725

1 272 0,9960784313725 0,9960784313725 0,9960784313725

1 271 0,9960784313725 0,9960784313725 0,9960784313725

1 270 0,9803921568627 1,0000000000000 0,9803921568627

1 269 0,9803921568627 1,0000000000000 0,9803921568627

1 268 0,9843137254902 1,0000000000000 0,9882352941176

1 267 0,9882352941176 1,0000000000000 0,9921568627451

1 266 0,9960784313725 1,0000000000000 1,0000000000000

1 263 0,9960784313725 0,9960784313725 1,0000000000000

1 257 0,9960784313725 1,0000000000000 1,0000000000000

1 256 0,9960784313725 1,0000000000000 1,0000000000000

1 255 0,9960784313725 1,0000000000000 1,0000000000000

1 254 0,9921568627451 0,9960784313725 1,0000000000000

readJPEG(…)

Page 8: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

applies statistical learning

kmeans(painting_rgb[,c(“R","G","B")],centers = number_of_colors, iter.max = 30)

Page 9: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

applies statistical learning

R B

G

Page 10: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

builds a palette

rgb_raw_palette <- k_means$centers final_palette <- rgb(k_means$centers)show_col(final_palette)

Page 11: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

builds a palette

no knowledge about relationships between colours

no order in colours

too dark and too bright colours

Page 12: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

interlude: rgb and hsv

By SharkD - Own work, GFDL, https://commons.wikimedia.org/w/index.php?curid=3375025

RGB

Page 13: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

interlude: rgb and hsv

By SharkD - Own work, GFDL, https://commons.wikimedia.org/w/index.php?curid=3375025

RGB

Hue

Value

HSV

Page 14: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

paletteR gots cleaver

• learning colours

• palette optimization based on variable type

Page 15: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

learning coloursrgb_raw_palette %>% t() %>% rgb2hsv() %>% t() %>% data.frame() %>% mutate(id = row.names(.)) -> hsv_raw_palette

Page 16: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

learning coloursrgb_raw_palette %>% data.frame() %>% mutate(id = row.names(.)) %>% left_join(hsv_raw_palette) %>% left_join(rgb_text_vector) %>% arrange(h,s,v) -> sorted_raw_palette

Page 17: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

learning coloursbrightness_stats <- boxplot.stats(sorted_raw_palette$v)saturation_stats <- boxplot.stats(sorted_raw_palette$s)first_quartile_v <- round(brightness_stats$stats[2],4) sorted_raw_palette %>% filter(v > first_quartile_v) -> sorted_raw_palette outlier_threshold_v <- brightness_stats$stats[5] sorted_raw_palette %>% filter(v < outlier_threshold_v) -> sorted_raw_palette sorted_raw_palette %>% filter(s > first_quartile_s) -> sorted_raw_palette

Page 18: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

palette optimization based on variable type

hue

dens

ity

Page 19: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

palette optimization based on variable type

categorical

• algorithmic creation of alternative samples of hues

• evaluation of relative divergence among contiguous colours

• selection of the best sequence hue

dens

ity

Page 20: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

palette optimization based on variable type

continuous

• hue distribution mode selection

• colours interpolation between mode and contiguous colour

hue

dens

ity

Page 21: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

the final palette

Page 22: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

how to use itdevtools::install_github("andreacirilloac/paletter")

library(paletter)

colours_vector <- create_palette(image_path = image_path,number_of_colors =32,type_of_variable = “categorical")

Page 23: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017

how to use itggplot(data = mtcars, aes(x = rownames(mtcars),y = hp,color = rownames(mtcars), fill = rownames(mtcars))) + geom_bar(stat = 'identity') + scale_color_manual(values = colours_vector) + scale_fill_manual(values=colours_vector)+ theme_minimal() + guides(size = FALSE) + theme(legend.position = "bottom") + labs(title = "disp vs hp")+ coord_flip()

Page 24: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017
Page 25: automatically build the perfect palette for you plot …...automatically build the perfect palette for you plot with paletteR Andrea Cirillo 9th MilanoR meeting, 20th November 2017