This is some of the codes I wrote to create my charts. Each chart has its own code right below it.
You can navigate through the site using the sidebar on desktop.
If some code is useful to you, please consider donating.
Random charts
Boa constrictor 🐍
Code - Click to view
# packages ----------------------------------------------------------------library(dplyr)library(ggplot2)library(geomtextpath)# data --------------------------------------------------------------------data <-data.frame(a =c(2.8,2.8,3.8,2.9,2.8,3,4.5,5.6,5.7,4.4,5.8))quote <-"'My drawing was not a picture of a hat. It was a picture of a <i>Boa constrictor</i> digesting an elephant.'"scatter =data.frame(x =runif(10000,-5,18),y =runif(10000,-1,1))# plot --------------------------------------------------------------------data %>%ggplot(aes(x = a))+geom_density(adjust =1,fill ="#784707",color ="#462e0a",size =3)+geom_textdensity(size =5, fontface =2, spacing =30,vjust =-0.35, hjust =0.2,label = quote,color ="#462e0a",rich =TRUE)+geom_segment(x =-2.5, xend =12, y =0, yend =0,size =3, color ="#462e0a",lineend ="round")+geom_point(x =11.95, y =0.002, size =0.5)+annotate("text", x =12, y =0, label ="- The Little Prince by\nAntoine de Saint-Exupéry\nBruno Mioto - @BrunoHMioto",hjust =1, vjust =1.2, fontface ="bold",color ="#462e0a")+scale_y_continuous(expand =c(0,0))+scale_x_continuous(limits =c(-2.5,12))+theme_void()+theme(panel.background =element_rect(fill ="#f7f8f8", color =NA) )+coord_cartesian(ylim =c(-.4,0.8), xlim =c(-4,13))ggsave("elephant.png", width =10, height =6)
Alcohol consumption 🍺
Code - Click to view
# packages ----------------------------------------------------------------library(dplyr)library(readr)library(ggplot2)library(elementalist)library(janitor)library(ggrepel)library(rcartocolor)library(ggforce)# data --------------------------------------------------------------------data <-read_csv("data/alcohol-consumption-by-15-19-year-old-males-vs-females.csv") %>%clean_names()countries <-read_csv("data/continents2.csv") %>%clean_names() %>%select(alpha_3, region)data2 <- data %>%rename(male =4,female =5) %>%filter(year ==2010,!is.na(male),!is.na(female)) %>%left_join(countries, by =c("code"="alpha_3"))data_points <-tibble(x =c(15,38,38),y =c(5,5,28))# plot --------------------------------------------------------------------data2 %>%ggplot(aes(x = female, y = male, color = region))+geom_abline(color ="grey")+geom_text_repel(aes(label =ifelse(entity =="Brazil", entity,"")),fontface ="bold",max.overlaps =40,min.segment.length =0,box.padding =0.6,show.legend =FALSE)+geom_text_repel(aes(label =ifelse(male >25| female>10, entity,"")),fontface ="bold",box.padding =0.3,max.overlaps =20,show.legend =FALSE)+geom_point(alpha =0.7, aes(size = population_historical_estimates))+annotate("text",x =30, y =30, label =paste0("\u2191 Men drink more\n\u2193 Women drink more"),angle =33,fontface ="bold", color ="grey")+ ggforce::geom_mark_hull(data = data_points, aes(x = x, y = y), color ="grey20", fill ="grey20",linetype ="dashed",alpha =0.1)+annotate("text",x =31.5, y =11.5, label ="A better\nworld?",lineheight =0.8,fontface ="bold",family ="Open Sans",color ="grey40")+guides(size ="none")+#rcartocolor::scale_color_carto_d(palette = "Bold")+scale_color_manual(values =c("#7f3c8d","#11a579","#3969ac","#e68310","#e73f74") )+scale_x_continuous(labels = scales::label_number(scale =1,suffix ="L"),expand =expansion(mult =c(0,0.05)))+scale_y_continuous(labels = scales::label_number(scale =1,suffix ="L"),expand =expansion(mult =c(0,0.05)))+labs(title ="Average alcohol consumption with 15-19 year old, 2010",subtitle ="Measured in litres of pure alcohol per year",x ="Avg alcohol consumption per capita (Females)",y ="Avg alcohol consumption per capita (Males)",color ="Continent",caption ="Bruno Mioto @BrunoHMioto - Data: WHO, Global Health Observatory (GHO)" )+theme_classic()+theme(plot.title.position ="plot",plot.title =element_text(face ="bold"),legend.margin =margin(0,0,0,0,"pt"),legend.text =element_text(margin =margin(0,5,0,0, unit ='pt')),legend.title =element_text(face ="bold"),axis.title =element_text(face ="bold"),axis.text =element_text(face ="bold", angle =c(1,3,-3,-5,6)),legend.position ="top",panel.grid.major =element_line_wiggle(2.5),panel.grid.minor =element_line_wiggle(2.5, color ="#f1f1f1"),axis.line =element_line_wiggle(3),text =element_text(family ="Open Sans") )+coord_cartesian(xlim =c(0,40),ylim =c(0,40))ggsave("test12_5.png", width =6, height =5)