SlideShare a Scribd company logo
How to use complimentary colors to level-up your graphs
The Colortools package
library(colortools)
triadic('steelblue')
[1] "4682B4" "B44682" "82B446"
Sample Data-set -> Gapminder
A tibble: 6 x 6
country continent year lifeExp pop gdpPercap
<fct> <fct> <int> <dbl> <int> <dbl>
1 Afghanistan Asia 1952 28.8 8425333 779.
2 Afghanistan Asia 1957 30.3 9240934 821.
3 Afghanistan Asia 1962 32.0 10267083 853.
4 Afghanistan Asia 1967 34.0 11537966 836.
5 Afghanistan Asia 1972 36.1 13079460 740.
6 Afghanistan Asia 1977 38.4 14880372 786.
Filtering the dataset and selecting the variables of interest
(RSA_BOT_NAM = gapminder%>%
filter(country %in% c('South Africa', 'Botswana','Namibia'))%>%
select(year,country,lifeExp)%>%
group_by(country)%>%
arrange(year,country)%>%
mutate(rate_of_change_lifexp = lifeExp/lag(lifeExp)-1) %>%
replace_na(list(rate_of_change_lifexp = 0))
)
A tibble: 36 x 4
Groups: country [3]
year country lifeExp rate_of_change_lifexp
<int> <fct> <dbl> <dbl>
1 1952 Botswana 47.6 0
2 1952 Namibia 41.7 0
3 1952 South Africa 45.0 0
4 1957 Botswana 49.6 0.0419
5 1957 Namibia 45.2 0.0839
6 1957 South Africa 48.0 0.0661
7 1962 Botswana 51.5 0.0383
8 1962 Namibia 48.4 0.0699
9 1962 South Africa 50.0 0.0410
10 1967 Botswana 53.3 0.0345
... with 26 more rows
Visual representation
Plotting the rate of pertaining to life expectancy of the countries South Africa,
Botswana and Namibia
Set Theme:
theme_set(theme_minimal())
RSA_BOT_NAM%>%
ggplot(aes(x = year, y = rate_of_change_lifexp))+
Geomerties
geom_line(aes(color = country),size = 1.2)+
Manually color the line plot:
scale_color_manual(values = c("4682B4", "B44682" ,"82B446"))+
Formatting:
scale_y_continuous(labels = scales::percent)+
labs(
title = 'Life expectancy',
subtitle = 'The destructive impact of the HIV-pandemic on the lifenexpen
tacy of three neighbouring countries',
y = 'Rate of change',
x = '',
caption = str_glue('Source:
Gapminder 2007')
)

More Related Content

PDF
Visualising Big Data
PDF
[KSC 2018] 관심 영역 기반 픽셀 아트 이미지 생성 (Saliency-based Pixel Art Image Generation)
PPTX
Integrating R and Power BI
PDF
Handling missing data and outliers
PDF
Company segmentation - an approach with R
PDF
How to read multiple excel files - With R
PPTX
Storytelling By Visualization
PDF
Comparing Co2 Emissions Around The Globe
Visualising Big Data
[KSC 2018] 관심 영역 기반 픽셀 아트 이미지 생성 (Saliency-based Pixel Art Image Generation)
Integrating R and Power BI
Handling missing data and outliers
Company segmentation - an approach with R
How to read multiple excel files - With R
Storytelling By Visualization
Comparing Co2 Emissions Around The Globe

Recently uploaded (20)

PDF
Data Engineering Interview Questions & Answers Cloud Data Stacks (AWS, Azure,...
PPTX
(Ali Hamza) Roll No: (F24-BSCS-1103).pptx
PDF
Navigating the Thai Supplements Landscape.pdf
PDF
Transcultural that can help you someday.
PPTX
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
PPTX
Leprosy and NLEP programme community medicine
PPT
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
PPTX
chrmotography.pptx food anaylysis techni
PPTX
SAP 2 completion done . PRESENTATION.pptx
PDF
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
PPT
DU, AIS, Big Data and Data Analytics.ppt
PDF
Global Data and Analytics Market Outlook Report
PPTX
QUANTUM_COMPUTING_AND_ITS_POTENTIAL_APPLICATIONS[2].pptx
PDF
OneRead_20250728_1808.pdfhdhddhshahwhwwjjaaja
PPTX
Steganography Project Steganography Project .pptx
PDF
Jean-Georges Perrin - Spark in Action, Second Edition (2020, Manning Publicat...
PPTX
modul_python (1).pptx for professional and student
PPT
Predictive modeling basics in data cleaning process
PPTX
Pilar Kemerdekaan dan Identi Bangsa.pptx
PDF
Data Engineering Interview Questions & Answers Batch Processing (Spark, Hadoo...
Data Engineering Interview Questions & Answers Cloud Data Stacks (AWS, Azure,...
(Ali Hamza) Roll No: (F24-BSCS-1103).pptx
Navigating the Thai Supplements Landscape.pdf
Transcultural that can help you someday.
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
Leprosy and NLEP programme community medicine
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
chrmotography.pptx food anaylysis techni
SAP 2 completion done . PRESENTATION.pptx
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
DU, AIS, Big Data and Data Analytics.ppt
Global Data and Analytics Market Outlook Report
QUANTUM_COMPUTING_AND_ITS_POTENTIAL_APPLICATIONS[2].pptx
OneRead_20250728_1808.pdfhdhddhshahwhwwjjaaja
Steganography Project Steganography Project .pptx
Jean-Georges Perrin - Spark in Action, Second Edition (2020, Manning Publicat...
modul_python (1).pptx for professional and student
Predictive modeling basics in data cleaning process
Pilar Kemerdekaan dan Identi Bangsa.pptx
Data Engineering Interview Questions & Answers Batch Processing (Spark, Hadoo...
Ad
Ad

Levelling up your chart skills

  • 1. How to use complimentary colors to level-up your graphs The Colortools package library(colortools) triadic('steelblue') [1] "4682B4" "B44682" "82B446" Sample Data-set -> Gapminder A tibble: 6 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786.
  • 2. Filtering the dataset and selecting the variables of interest (RSA_BOT_NAM = gapminder%>% filter(country %in% c('South Africa', 'Botswana','Namibia'))%>% select(year,country,lifeExp)%>% group_by(country)%>% arrange(year,country)%>% mutate(rate_of_change_lifexp = lifeExp/lag(lifeExp)-1) %>% replace_na(list(rate_of_change_lifexp = 0)) ) A tibble: 36 x 4 Groups: country [3] year country lifeExp rate_of_change_lifexp <int> <fct> <dbl> <dbl> 1 1952 Botswana 47.6 0 2 1952 Namibia 41.7 0 3 1952 South Africa 45.0 0 4 1957 Botswana 49.6 0.0419 5 1957 Namibia 45.2 0.0839 6 1957 South Africa 48.0 0.0661 7 1962 Botswana 51.5 0.0383 8 1962 Namibia 48.4 0.0699 9 1962 South Africa 50.0 0.0410 10 1967 Botswana 53.3 0.0345 ... with 26 more rows Visual representation Plotting the rate of pertaining to life expectancy of the countries South Africa, Botswana and Namibia Set Theme: theme_set(theme_minimal()) RSA_BOT_NAM%>% ggplot(aes(x = year, y = rate_of_change_lifexp))+ Geomerties geom_line(aes(color = country),size = 1.2)+ Manually color the line plot: scale_color_manual(values = c("4682B4", "B44682" ,"82B446"))+
  • 3. Formatting: scale_y_continuous(labels = scales::percent)+ labs( title = 'Life expectancy', subtitle = 'The destructive impact of the HIV-pandemic on the lifenexpen tacy of three neighbouring countries', y = 'Rate of change', x = '', caption = str_glue('Source: Gapminder 2007') )