{"id":14068042,"url":"https://github.com/afrimapr/afrilearndata","last_synced_at":"2025-07-30T02:32:50.226Z","repository":{"id":80430724,"uuid":"307471995","full_name":"afrimapr/afrilearndata","owner":"afrimapr","description":"small african spatial datasets for learning \u0026 teaching mapping in R","archived":false,"fork":false,"pushed_at":"2021-11-09T15:16:49.000Z","size":6382,"stargazers_count":15,"open_issues_count":6,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-13T07:14:11.626Z","etag":null,"topics":["map","r","rstats","spatial","teaching","visualization"],"latest_commit_sha":null,"homepage":"https://afrimapr.github.io/afrilearndata","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/afrimapr.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-26T18:42:03.000Z","updated_at":"2023-08-25T13:34:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f0d01e6-a8a5-4d6e-a18d-abb5d3d4dbfc","html_url":"https://github.com/afrimapr/afrilearndata","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afrimapr%2Fafrilearndata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afrimapr%2Fafrilearndata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afrimapr%2Fafrilearndata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afrimapr%2Fafrilearndata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afrimapr","download_url":"https://codeload.github.com/afrimapr/afrilearndata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228075704,"owners_count":17865529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["map","r","rstats","spatial","teaching","visualization"],"created_at":"2024-08-13T07:05:54.727Z","updated_at":"2024-12-04T08:31:31.293Z","avatar_url":"https://github.com/afrimapr.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\u003c!-- used devtools::build_readme() to update the md --\u003e\n\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# afrilearndata \u003ca href='https://github.com/afrimapr/afrilearndata'\u003e\u003cimg src='man/figures/hex.png' align=\"right\" height=\"139\" /\u003e\u003c/a\u003e \n\n\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\nafrilearndata provides small African spatial datasets to help with learning and teaching of spatial techniques and mapping.\n\nThe motivation is to provide analysts based in Africa with more easily relateable example datasets. More generally we aim to support the growth of R and mapping in the continent. Part of the [afrimapr](https://afrimapr.github.io/afrimapr.website/) project providing R building blocks, training and community.\n\n## Installation\n\nInstall the development version of afrilearndata with:\n\n```{r setup, eval=FALSE, message=FALSE, warning=FALSE}\n\n    # install.packages(\"remotes\") # if not already installed\n    \n    remotes::install_github(\"afrimapr/afrilearndata\")\n    \n    library(afrilearndata)\n\n```\n\n## Datasets\n\nThe package contains the following objects \n\n1. `africontinent`    polygons, continent outline including madagascar\n1. `africountries`    polygons, 51 country boundaries\n1. `afrihighway`         lines, trans African highway network (100 lines)\n1. `africapitals`     points, 51 capital cities\n1. `afriairports`     points, \u003e3000 African airports\n1. `afripop2020`   raster grid, population density 2020 from [WorldPop](https://www.worldpop.org/) aggregated to 20km squares\n1. `afripop2000`   raster grid, population density 2000 from [WorldPop](https://www.worldpop.org/) aggregated to 20km squares\n1. `afrilandcover`   raster grid, landcover in 2019, categorical, 20km from [MODIS](https://lpdaac.usgs.gov/products/mcd12c1v006/) \n\nLazy loading means that the objects should be accessible once `library(afrilearndata)` is used.\n\nIf they are not recognised you can use e.g. `data(africountries)` to make sure the objects are loaded.\n\nAs well as providing the data as R objects the package provides them as files that can be used to demonstrate the process of reading spatial data into R and the read code is provided in the documentation of each dataset. The different datasets cover the following formats commonly used to store sptial data : geopackage, shapefile, kml, tiff, csv and grd.    \n\nFirstly, here are most of the data shown together. The `tmap` code to create this plot is shown later in the readme. \n\n```{r tmap-all-the-data, echo=FALSE, message=FALSE, warning=FALSE}\n#echo=FALSE to not show code in first version at top of readme\n#do show the code later\n\nlibrary(afrilearndata)\n\n# install.packages(\"tmap\") # if not already installed\nlibrary(tmap)\n\n# tmap_mode(\"view\") to set to tmap interactive viewing mode\n\ntm_shape(afripop2020) +\n    tm_raster(palette = rev(viridisLite::magma(5)), breaks=c(0,2,20,200,2000,25000)) +\ntm_shape(africountries) +\n    tm_borders(\"white\", lwd = .5) +\n    #tm_text(\"iso_a3\", size = \"AREA\") +\ntm_shape(afrihighway) +\n    tm_lines(col = \"black\") + \ntm_shape(africapitals) +\n    tm_symbols(col = \"blue\", alpha=0.4, scale = .6 )+\ntm_legend(show = FALSE)\n\n```\n\nNow looking at the data layers individually plotted with packages `sf` or `raster`\n\n```{r countries, message=FALSE, warning=FALSE}\n\nlibrary(afrilearndata)\nlibrary(sf)\n\n# polygons\nplot(sf::st_geometry(africountries))\n\n```\n\n```{r highway, message=FALSE, warning=FALSE}\n\n# lines\nplot(sf::st_geometry(afrihighway))\n\n```\n\n```{r capitals, message=FALSE, warning=FALSE}\n\n# points\nplot(sf::st_geometry(africapitals))\n\n```\n\n\nPopulation density data are from WorldPop clipped to Africa and aggregated to 20km resolution to make them more manageable. [WorldPop](https://www.worldpop.org/) datasets are licensed under [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/).\n\n\n```{r population-grid, message=FALSE, warning=FALSE}\n\n# raster grid\n# install.packages(\"raster\") # if not already installed\nlibrary(raster)\nplot(afripop2020)\n\n```\n\nThe `africountries` data has country names in French, Portuguese, Swahili, Afrikaans and English, that can be used to label maps as follows.\n\n```{r french-country-names, warnings=FALSE, eval=TRUE, echo=TRUE}\n\nlibrary(afrilearndata)\n\n# install.packages(\"tmap\") # if not already installed\nlibrary(tmap)\n\ntm_shape(africountries) +\n     tm_borders(\"grey\", lwd = .5) +\n     tm_text(\"name_fr\", auto.placement=FALSE, remove.overlap=FALSE, just='centre', col='red4', size=0.7 )\n```\n\nInteractive maps can be created using the `mapview` package.\n\n```{r interactive, eval=FALSE}\n\n# install.packages(\"mapview\") # if not already installed\n\nlibrary(mapview)\nmapview::mapview(africountries, zcol=\"name\")\n#here to show all airports on the continent\nmapview(afriairports, zcol='type', label='name', cex=2)\n  \n```\n\nLandcover data for the continent is provided as the majority landcover in 2019 at 20km resolution obtained from [MODIS](https://lpdaac.usgs.gov/products/mcd12c1v006/). An interactive landcover map can be displayed with `mapview`.\n\n```{r interactive-landcover, eval=FALSE}\n\n# install.packages(\"mapview\") # if not already installed\n\nlibrary(mapview)\n\nmapview(afrilandcover,\n       att=\"landcover\",\n       col.regions=levels(afrilandcover)[[1]]$colour)\n  \n```\n\n\n\nHere is a repeat of the map shown at the start of the readme, together with the code used to create it.\n\n```{r tmap-code, warnings=FALSE, eval=TRUE, echo=TRUE}\n\nlibrary(afrilearndata)\n\n# install.packages(\"tmap\") # if not already installed\nlibrary(tmap)\n\n# tmap_mode(\"view\") to set to tmap interactive viewing mode\n\ntm_shape(afripop2020) +\n    tm_raster(palette = rev(viridisLite::magma(5)), breaks=c(0,2,20,200,2000,25000)) +\ntm_shape(africountries) +\n    tm_borders(\"white\", lwd = .5) +\ntm_shape(afrihighway) +\n    tm_lines(col = \"red\") + \ntm_shape(africapitals) +\n    tm_symbols(col = \"blue\", alpha=0.4, scale = .6 )+\ntm_legend(show = FALSE)\n\n```\n\n## Learning Resources\n\nFor learning resources using these data see our [afrilearnr interactive tutorials](https://github.com/afrimapr/afrilearnr), resources in English \u0026 French for a [4 hour entry level tutorial](https://github.com/afrimapr/r-maps-tutorial-fr-eng) and the in-progress [afrimapr book](https://github.com/afrimapr/afrimapr-book).\n\n## How were the datasets created ?\n\nHere is the [code (somewhat untidy)](https://github.com/afrimapr/afrilearndata/blob/master/data-raw/afrilearndata-data-creation.R) to create the datasets in the package.\n\n## Related\n\nFor other and larger spatial datasets see the [spData package](https://github.com/Nowosad/spData) which was part of the inspiration for afrilearndata.\n\n## Contributions\n\nafrilearndata is part of [afrimapr](https://afrimapr.github.io/afrimapr.website/) we welcome \n[issues and enhancement requests](https://github.com/afrimapr/afrilearndata/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafrimapr%2Fafrilearndata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafrimapr%2Fafrilearndata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafrimapr%2Fafrilearndata/lists"}