Git Product home page Git Product logo

africacountrybins's Introduction

AfricaCountryBins

Create Uniform Square Country Cartogram heatmaps

Description

Heatmaps in a tile shape are an alternative to choropleth maps that don’t distort perception of results based on land mass size.

This package is a essentially a fork of Bob Rudis’s statebins package designed for use for data involving Africa.

This grid attempts to preserve the general position of countries on the continent, while providing an equal area by country.

Whatcha Get?

The main function implemented is - geom_countrybins_africa: which is a countrybin Geom for africa

Installation

Use the following to install:

devtools::install_github("delabj/AfricaCountryBins")
# or 
remotes::install_github("delabj/AfricaCountryBins")

To use these options you’ll have to install devtools or remotes respectively.

Examples

library(AfricaCountryBins)
library(hrbrthemes)
library(tidyverse)

data("africa_mines")

count(africa_mines, countrycode, wt=count) %>%
  mutate(n = ifelse(n == 0, NA, n)) %>%
  ggplot(aes(country = countrycode, fill = n)) +
  geom_countrybins_africa() +
  coord_fixed() +
  scale_fill_viridis_c(
    name = "# mines (log2)",
    option = "magma",
    direction = -1,
    na.value = "#DEE5E8",
    trans = "log2",
    label = scales::comma_format(1)
  ) +
  guides(
    fill = guide_colourbar(
      title.position = "top"
    )
  ) +
  labs(
    title = "Mines in Africa",
    caption = "Source: data.world <hdata.world/datainspace/mines-in-africa>"
  ) +
  theme_ipsum_es(grid="") +
  theme(legend.position = c(0.2, 0.4)) +
  theme(legend.direction = "horizontal") +
  theme(legend.key.width = unit(1.5, "lines")) +
  theme(axis.text.x = element_blank()) +
  theme(axis.text.y = element_blank()) +
  theme(plot.title = element_text(hjust = 0.5))

africa_mines %>%
  count(countrycode, mine_type, wt = count) %>%
  mutate(mine_type = fct_reorder(mine_type, n, sum)) %>%
  filter(mine_type %in% rev(levels(mine_type))[1:8]) %>%
  mutate(n = ifelse(n == 0, NA, n)) %>%
  ggplot(aes(country = countrycode, fill = n)) +
  geom_countrybins_africa(
    radius = unit(0, "pt"),
    family = font_an, size = 2
  ) +
  scale_fill_viridis_c(
    name = "# mines (log2)",
    option = "magma",
    direction = -1,
    na.value = "#DEE5E8",
    trans = "log2",
    label = scales::comma_format(1)
  ) +
  coord_equal() +
  facet_wrap(~mine_type) +
  guides(
    fill = guide_colourbar(
      title.position = "top"
    )
  ) +
  labs(
    title = "Mines in Africa",
    caption = "Source: data.world <hdata.world/datainspace/mines-in-africa>"
  ) +
  theme_ipsum(grid="", strip_text_face = "bold") +
  theme(legend.position = c(0.85, 0.2)) +
  theme(legend.direction = "vertical") +
  theme(axis.text.x = element_blank()) +
  theme(axis.text.y = element_blank())

africacountrybins's People

Contributors

delabj avatar hrbrmstr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.