Have you ever felt a little unsure about which colors to use for your graphs?
This is the case for me so many times until I found the package : colortools. It shows you which colors are complimentary to each other.
Have a look and see how to change that!
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
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')
)