Skip to content

Instantly share code, notes, and snippets.

@ikashnitsky
Last active January 24, 2018 05:14
Show Gist options
  • Save ikashnitsky/2f6e29acbb9cbeb1694630c5932b8ad5 to your computer and use it in GitHub Desktop.
Save ikashnitsky/2f6e29acbb9cbeb1694630c5932b8ad5 to your computer and use it in GitHub Desktop.
Global convergence in male life expectancy at birth since 1950
################################################################################
#
# ikashnitsky.github.io 2017-07-17
# Trying ggjoy.
# The world convergence in male life expectancy at birth since 1950
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
library(tidyverse)
library(forcats)
library(wpp2015)
library(ggjoy)
library(viridis)
library(extrafont)
data(UNlocations)
countries <- UNlocations %>%
filter(location_type == 4) %>%
transmute(name = name %>% paste()) %>%
as_vector()
data(e0M)
e0M %>%
filter(country %in% countries) %>%
select(-last.observed) %>%
gather(period, value, 3:15) %>%
ggplot(aes(x = value, y = period %>% fct_rev()))+
geom_joy(aes(fill = period))+
scale_fill_viridis(discrete = T, option = "B", direction = -1,
begin = .1, end = .9)+
labs(x = "Male life expectancy at birth",
y = "Period",
title = "The world convergence in male life expectancy at birth since 1950",
subtitle = "Data: UNPD World Population Prospects 2015 Revision",
caption = "ikashnitsky.github.io")+
theme_minimal(base_family = "Roboto Condensed", base_size = 15)+
theme(legend.position = "none")
@PCK1992
Copy link

PCK1992 commented Jul 18, 2017

When I try to run lines 29 to 43 I get the following error:

Error in eval(substitute(list(...)), _data, parent.frame()) :
object 'height' not found
In addition: Warning message:
In max(data$height) : no non-missing arguments to max; returning -Inf

@vshatalov
Copy link

It's very interesting work. I've done something like this by mining Wikipedia data. I wonder would the results be close?

@emilelatour
Copy link

I got a similar error as PCK1992. I resolved it by re-installing ggjoy package. It had been working fine for me the other day and this was what fixed it. Could have also been the restart of RStudio too.

@PCK1992
Copy link

PCK1992 commented Jul 19, 2017

emilelatour that worked for me, too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment