Skip to content

Commit

Permalink
updated life_expec data + long format
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed May 13, 2024
1 parent d0fac7c commit 3a3a103
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
9 changes: 9 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@
#' @source gapminder package (\url{https://jennybc.github.io/gapminder/} and \url{https://www.gapminder.org/data/})
"life_expec"

#' @title Life expectancy data (long format)
#'
#' @description The dataset contains data about life expectancy in 1972 and 2007 for 10 countries.
#'
#' @format A data frame with 20 observations and 3 variables.
#'
#' @source gapminder package (\url{https://jennybc.github.io/gapminder/} and \url{https://www.gapminder.org/data/})
"life_expec_long"

23 changes: 13 additions & 10 deletions data-raw/life_expectancy.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ library(gapminder)

# Data --------------------------------------------------------------------

life_expec <- as.data.table(gapminder::gapminder)
life_expec <- life_expec[year %in% c(1972, 2007), list(country, year, lifeExp)]
life_expec_long <- as.data.table(gapminder::gapminder)
life_expec_long <- life_expec_long[year %in% c(1972, 2007), list(country, year, lifeExp)]

# life_expec <- life_expec[country %in% sample(unique(country), 10)]
life_expec <- life_expec[country %in% c("Botswana", "Ghana", "Iran", "Liberia", "Malaysia", "Mexico",
life_expec_long <- life_expec_long[country %in% c("Botswana", "Ghana", "Iran", "Liberia", "Malaysia", "Mexico",
"Nigeria", "Pakistan", "Philippines", "Zambia")]
life_expec <- dcast(life_expec, country ~ year, value.var = "lifeExp")
life_expec_long[, country := as.character(country)]
life_expec <- dcast(life_expec_long, country ~ year, value.var = "lifeExp")
life_expec[, type := fifelse(`1972` > `2007`, "decreased", "increased")]


Expand All @@ -25,6 +26,8 @@ life_expec[, type := fifelse(`1972` > `2007`, "decreased", "increased")]
setDF(life_expec)
usethis::use_data(life_expec, internal = FALSE, overwrite = TRUE, compress = "xz")

setDF(life_expec_long)
usethis::use_data(life_expec_long, internal = FALSE, overwrite = TRUE, compress = "xz")



Expand All @@ -34,13 +37,13 @@ usethis::use_data(life_expec, internal = FALSE, overwrite = TRUE, compress = "xz

pkgload::load_all()

apex(life_expec, aes(country, x = `1972`, xend = `2007`), type = "dumbbell") %>%
apex(life_expec, aes(country, x = `1972`, xend = `2007`), type = "dumbbell") %>%
ax_plotOptions(
bar = bar_opts(
dumbbellColors = list(list("#3d85c6", "#fb6003"))
)
) %>%
ax_colors("#BABABA") %>%
) %>%
ax_colors("#BABABA") %>%
ax_labs(
title = "Life expectancy : 1972 vs. 2007",
subtitle = "Data from Gapminder dataset",
Expand All @@ -49,14 +52,14 @@ apex(life_expec, aes(country, x = `1972`, xend = `2007`), type = "dumbbell") %>%



apex(life_expec, aes(country, x = `1972`, xend = `2007`, group = type), type = "dumbbell") %>%
apex(life_expec, aes(country, x = `1972`, xend = `2007`, group = type), type = "dumbbell") %>%
ax_xaxis(type = "category", categories = unique(life_expec$country)) %>%
ax_plotOptions(
bar = bar_opts(
dumbbellColors = list(list("#3d85c6", "#fb6003"), list("#3d85c6", "#fb6003"))
)
) %>%
ax_colors(c("#3d85c6", "#fb6003")) %>%
) %>%
ax_colors(c("#3d85c6", "#fb6003")) %>%
ax_labs(
title = "Life expectancy : 1972 vs. 2007",
subtitle = "Data from Gapminder dataset",
Expand Down
Binary file modified data/life_expec.rda
Binary file not shown.
Binary file added data/life_expec_long.rda
Binary file not shown.
19 changes: 19 additions & 0 deletions man/life_expec_long.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a3a103

Please sign in to comment.