library(tidytuesdayR)
library(tidyverse)
library(showtext)
library(ggtext)
library(scales)
library(extrafont)
library(patchwork)
library(cowplot)
library(ragg)
library(rmarkdown)
library(hrbrthemes)
library(wesanderson)
Load libraries
Load Datasets
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-03-30/sephora.csv')
sephora <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-03-30/ulta.csv')
ulta
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-03-30/allCategories.csv')
allCategories <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-03-30/allShades.csv')
allShades <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-03-30/allNumbers.csv') allNumbers
Load fonts
loadfonts()
font_add_google(name = "Amatic SC", family = "amatic-sc")
font_add_google("Cedarville Cursive", "cedarville")
showtext_auto(enable = TRUE)
<- c("#FF0000","#FF7070","#F09200","#FFBF1F","#00A08A","#2989A3","#5BBCD6","#A475D9") palette
Manipulation of data
<-sephora%>%
sephora_submutate(shop=rep("sephora",length(brand)),
brand=tolower(brand),
product=tolower(product),
name=tolower(name))%>%
select(brand,product,name)
<-ulta%>%
ulta_submutate(shop=rep("ulta",length(brand)),
brand=tolower(brand),
product=tolower(product),
name=tolower(name))%>%
select(brand,product,name)
<-rbind(sephora_sub,ulta_sub) shops
Manipulation of data
<-allCategories%>%
allCategories_submutate(brand=tolower(brand),
product=tolower(product),
name=tolower(name))%>%
separate_rows(categories, convert = TRUE) %>%
mutate(categories = fct_reorder(categories, lightness)) %>%
select(brand,product,name,hex,lightness,categories)
<-allShades%>%
allShades_submutate(brand=tolower(brand),
product=tolower(product),
name=tolower(name))%>%
select(brand,product,name,hex,hue,sat,lightness)
<-allNumbers%>%
allNumbers_submutate(brand=tolower(brand),
product=tolower(product),
name=tolower(name))%>%
select(brand,product,name,hex,lightness,lightToDark)
################### Full Join of the datasets ##############
<-full_join(allCategories_sub,allShades_sub,by.x=hex,by.y=lightness)
make_up<-full_join(make_up,allNumbers_sub,by.x=hex,by.y=lightness)
make_up
<-make_up%>%
make_up_subselect(brand,name,hex,hue,sat,lightness)%>%
filter(!is.na(hue))%>%
arrange(hex)
Counting uniqueness
::count(make_up$brand); #107
plyr::count(make_up$product);#328
plyr::count(make_up$name);#1,317
plyr::count(allCategories_sub$categories)#17 plyr
Selection of data for making plots
<- sort(c("shiseido","maybelline","mac","lancôme","l'oréal","guerlain","estée lauder","clinique","benefit cosmetics"), decreasing = TRUE)
my_companies
<- make_up_sub %>%
make_up_for_plot filter(brand %in% my_companies) %>%
select(brand, name,hex, hue,sat,lightness) %>%
mutate(brand=as.factor(brand)) %>%
group_by(brand) %>%
mutate(mean_lightness = mean(lightness)) %>%
ungroup() %>%
mutate(brand = fct_reorder(brand, mean_lightness))
library(ggfx)
library(gridExtra)
<-make_up_for_plot%>%
plot1ggplot(aes(brand,lightness,col=hex)) +
with_blur(
geom_boxplot(size=5,show.legend = FALSE)) +
geom_jitter(width = 0.15,height = 0.0,size = 1) +
scale_colour_identity() +
coord_polar() +
labs(title = "Shades of makeup from The Pudding",
subtitle = "All collected from the US versions of Sephora and Ulta’s websites",
caption = "107 brands, 328 products, 317 names and 17 categories",
tag = "The Pudding",
x = "Lightness",
y = "Brands)",
colour = "white")+
theme_void(base_family = "cedarville") +
theme(plot.background = element_rect(fill = "black",color="black"),
axis.text.x = element_text(size = 30, vjust = 2,color="white"),
plot.title = element_text(size = 56,hjust = 0.5,color="white"),
plot.subtitle = element_text(size = 46,hjust = 0.5,color="white"),
plot.caption = element_text(size = 36,hjust = 0.5,
margin = margin(t = 5, b = 10),color="white"),
plot.tag = element_text()
)
<-make_up_for_plot%>%
plot2ggplot(aes(brand,lightness,col=hex)) +
with_blur(
geom_point(show.legend = FALSE)) +
geom_jitter(width = 0.15,height = 0.0,size = 2) +
scale_colour_identity() +
coord_polar(direction=1) +
theme_void() +
theme(plot.background = element_rect(fill = "black")) +
facet_wrap(vars(brand))
Final plot
library(ggimage)
require(magick)
<- plot1 + plot2
main_plot
<- main_plot +
final labs(title = "Makeup - The naked truth",
subtitle = "combination for naming their shades",
caption = "TidyTuesday W14 - The Pudding - Viz - @fgazzelloni") +
scale_fill_manual(values = palette,
guide = guide_legend(title = NULL)) +
theme_void(base_family = "cedarville") +
theme(plot.background = element_rect(fill = "#FCEBDA",color = NA),
strip.text.x = element_text(color = NA),
axis.text.x = element_text(size = 20, vjust = 2),
panel.grid.major = element_line(size = 0.03, linetype = 'solid',colour = "black"),
plot.margin = margin(10, 10, 5, 10),
plot.title = element_text(size = 56,hjust = 0.5, margin = margin(t = 5, b = 10)),
plot.subtitle = element_text(size = 40,hjust = 0.5),
plot.caption = element_text(hjust = 0.5, size = 26))
Save the plot in a .png file
::agg_png(here::here("w14_the_pudding", "w14_the_pudding.png"),
raggres = 320, width = 14, height = 8, units = "in")
final
dev.off()
Read the image, attach the Tidytuesday logo and save it
<- image_read("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/static/plot_logo.png") %>%
tidy_logo image_resize("300x300")
<- image_read(here::here("w14_the_pudding/w14_the_pudding.png"))
The_Pudding_plot
<- image_composite(The_Pudding_plot, tidy_logo,
attached_logo operator="atop",
gravity="southeast") # tell R where to put the logo
image_write(attached_logo,
path = "/Users/federica/Documents/R/R_general_resourses/TidyTuesday/TidyTuesday/w14_the_pudding/w14_the_pudding.png", format = "png") # save final plot