Created
April 4, 2021 14:49
-
-
Save fernandobarbalho/72137bd127d047ea0f293b3bd87d997d to your computer and use it in GitHub Desktop.
Code to Pixar Text on Medium
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
# Install from CRAN | |
install.packages("pixarfilms") | |
# Install directly from GitHub | |
remotes::install_github("erictleung/pixarfilms") | |
library(pixarfilms) | |
library(tidyverse) | |
pixar_all<- | |
pixar_films %>% | |
inner_join(genres) %>% | |
inner_join(pixar_people) %>% | |
inner_join(box_office) %>% | |
inner_join(public_response) | |
##Avaliação do público por avaliadores | |
public_response %>% | |
select(-cinema_score) %>% | |
pivot_longer(-film, names_to = "critics", values_to = "grade") %>% | |
mutate(critics = factor(critics, labels= c("Rotten tomatoes", "Metacritic", "Critics choice" ), levels = c("rotten_tomatoes", "metacritic", "critics_choice" ))) %>% | |
mutate(film= reorder(film, grade, FUN = sum)) %>% | |
ggplot(aes(y=film, x= grade)) + | |
geom_col(fill = "#FFEF03", color= "#FD0B0A") + | |
facet_wrap(critics~.) + | |
theme_light() + | |
theme( | |
panel.background = element_rect(fill = "black"), | |
panel.grid = element_blank(), | |
axis.text.y = element_text(color = "#FD0B0A"), | |
axis.text.x = element_text(color = "#203DBD"), | |
strip.background = element_rect(fill = "white"), | |
strip.text = element_text(color = "#203DBD"), | |
axis.title = element_blank() | |
) | |
library(ggrepel) | |
#timeline | |
pixar_all %>% | |
distinct(film, release_date, budget, box_office_worldwide) %>% | |
rename(`box office worldwide` = box_office_worldwide ) %>% | |
pivot_longer(-c(1,2),names_to = "money", values_to = "value" ) %>% | |
mutate(value = value/10^6) %>% | |
ggplot(aes(x= release_date, y=value,fill= money )) + | |
geom_col(color= "#203DBD") + | |
#geom_text(aes(label = film), color = "white", position = "stack", vjust =0)+ | |
scale_fill_manual(values= c("#FFEF03","#FD0B0A"))+ | |
scale_x_date(date_breaks = "1 year", date_labels = "%Y",guide = guide_axis(n.dodge = 2)) + | |
theme_light() + | |
theme( | |
panel.background = element_rect(fill = "black"), | |
panel.grid = element_blank(), | |
legend.position = "bottom" | |
) + | |
labs( x= "Release date", | |
y="Box-office worldwide (US$ mi)")+ | |
annotate("text", x= as.Date("1995-11-22"), y= 450, label= "Toy Story", color = "#FD0B0A", fontface = "bold")+ | |
annotate("text", x= as.Date("2018-06-15"), y= 1480, label= "Incredibles 2", color = "#FD0B0A", fontface = "bold")+ | |
annotate("text", x= as.Date("2010-06-18"), y= 1310, label= "Toy Story 3", color = "#FD0B0A", fontface = "bold")+ | |
annotate("text", x= as.Date("2019-06-21"), y= 1310, label= "Toy Story 4", color = "#FD0B0A",hjust = 0.2, fontface = "bold" )+ | |
annotate("text", x= as.Date("2020-12-25"), y= 300, label= "Soul", color = "#FD0B0A",hjust = 0.2 , fontface = "bold") | |
#scattering budget x Box-office | |
pixar_all %>% | |
distinct(film, budget, box_office_worldwide) %>% | |
ggplot(aes(x=budget/10^6, y=box_office_worldwide/10^6)) + | |
geom_point(size =6, fill = "#FFEF03", color = "#203DBD", pch= 21 )+ | |
geom_text_repel(aes(label = str_wrap(film,15)), color= "#FD0B0A", fontface= "bold", set.seed = 1972, box.padding = unit(1, "lines")) + | |
theme_light() + | |
theme( | |
panel.background = element_rect(fill = "black"), | |
panel.grid = element_blank() | |
) + | |
labs( x= "Budget (US$ mi)", | |
y="Box-office worldwide (US$ mi)") | |
#scattering budget X public response | |
pixar_all %>% | |
distinct(film, budget, rotten_tomatoes,metacritic, critics_choice) %>% | |
pivot_longer(-c(film, budget), names_to = "critics", values_to = "grade") %>% | |
group_by(film) %>% | |
summarise( | |
budget = max(budget), | |
grade = mean(grade, na.rm = TRUE) | |
) %>% | |
ungroup() %>% | |
ggplot(aes(x=budget/10^6, y =grade)) + | |
geom_point(size =6, fill = "#FFEF03", color = "#203DBD", pch= 21 )+ | |
geom_text_repel(aes(label = str_wrap(film,15)), fontface= "bold", color= "#FD0B0A",box.padding = unit(1, "lines")) + | |
theme_light() + | |
theme( | |
panel.background = element_rect(fill = "black"), | |
panel.grid = element_blank() | |
) + | |
labs( x= "Budget (US$ mi)", | |
y="Grade") | |
#scattering grade X box-office | |
pixar_all %>% | |
distinct(film, box_office_worldwide, rotten_tomatoes,metacritic, critics_choice) %>% | |
pivot_longer(-c(film, box_office_worldwide), names_to = "critics", values_to = "grade") %>% | |
group_by(film) %>% | |
summarise( | |
box_office_worldwide = max(box_office_worldwide), | |
grade = mean(grade, na.rm = TRUE) | |
) %>% | |
ungroup() %>% | |
ggplot(aes(y=box_office_worldwide/10^6, x =grade)) + | |
geom_point(size =6, fill = "#FFEF03", color = "#203DBD", pch= 21 )+ | |
geom_text_repel(aes(label = str_wrap(film,15)), fontface= "bold", color= "#FD0B0A",box.padding = unit(1, "lines")) + | |
theme_light() + | |
theme( | |
panel.background = element_rect(fill = "black"), | |
panel.grid = element_blank() | |
) + | |
labs( y= "Box-office worldwide (US$ mi)", | |
x="Grade") | |
people_20<- | |
pixar_all %>% | |
mutate(name= case_when( | |
name == "Stanton" ~ "Andrew Stanton", | |
name=="Docter" ~ "Pete Docter", | |
name=="Lasseter" ~ "John Lasseter", | |
name=="Unkrich" ~ "Lee Unkrich", | |
name=="Scanlon" ~ "Dan Scanlon", | |
TRUE ~ name)) %>% | |
group_by(name) %>% | |
summarise( | |
quant= n() | |
) %>% | |
ungroup()%>% | |
slice_max(order_by = quant, n=20) %>% | |
select(name) | |
pixar_all %>% | |
mutate(name= case_when( | |
name == "Stanton" ~ "Andrew Stanton", | |
name=="Docter" ~ "Pete Docter", | |
name=="Lasseter" ~ "John Lasseter", | |
name=="Unkrich" ~ "Lee Unkrich", | |
name=="Scanlon" ~ "Dan Scanlon", | |
TRUE ~ name)) %>% | |
inner_join(people_20) %>% | |
group_by(name, role_type) %>% | |
summarise( | |
quant= n() | |
) %>% | |
ungroup()%>% | |
#slice_max(order_by = quant, n=35) %>% | |
mutate(name= fct_reorder(name, quant, sum) ) %>% | |
#arrange(desc(name)) %>% | |
ggplot(aes(y=name, x= quant,fill= role_type)) + | |
geom_col(color= "#EA623B") + | |
scale_fill_manual(values= c("#628528", "#FD0B0A", "#203DBD", "#FDA40C", "#FFEF03"))+ | |
theme_light() + | |
theme( | |
panel.background = element_rect(fill = "black"), | |
panel.grid = element_blank(), | |
axis.text.y = element_text(color = "#FD0B0A"), | |
axis.text.x = element_text(color = "#203DBD"), | |
axis.title = element_blank(), | |
legend.position = "bottom" | |
) + | |
labs( fill = "Role type") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment