{"id":13425156,"url":"https://github.com/paezha/spatial-analysis-r","last_synced_at":"2025-04-09T07:06:25.246Z","repository":{"id":42078845,"uuid":"391072865","full_name":"paezha/spatial-analysis-r","owner":"paezha","description":"Open Educational Resource for teaching spatial data analysis and statistics with R","archived":false,"fork":false,"pushed_at":"2025-01-10T13:29:10.000Z","size":156373,"stargazers_count":71,"open_issues_count":2,"forks_count":25,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-31T18:22:21.636Z","etag":null,"topics":["data-analysis","open-educational-resource","r","r-package","r-spatial","rstats","spatial-data-analysis","spatial-statistics","statistics"],"latest_commit_sha":null,"homepage":"https://paezha.github.io/spatial-analysis-r/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paezha.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-07-30T13:23:28.000Z","updated_at":"2025-03-25T21:13:59.000Z","dependencies_parsed_at":"2025-03-15T19:43:02.755Z","dependency_job_id":null,"html_url":"https://github.com/paezha/spatial-analysis-r","commit_stats":{"total_commits":144,"total_committers":3,"mean_commits":48.0,"dds":0.02777777777777779,"last_synced_commit":"980b8e095d2648332834def4cb272ac8daaa1776"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paezha%2Fspatial-analysis-r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paezha%2Fspatial-analysis-r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paezha%2Fspatial-analysis-r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paezha%2Fspatial-analysis-r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paezha","download_url":"https://codeload.github.com/paezha/spatial-analysis-r/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994119,"owners_count":21030050,"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":["data-analysis","open-educational-resource","r","r-package","r-spatial","rstats","spatial-data-analysis","spatial-statistics","statistics"],"created_at":"2024-07-31T00:01:06.238Z","updated_at":"2025-04-09T07:06:25.219Z","avatar_url":"https://github.com/paezha.png","language":"HTML","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\u003c!-- IMPORTANT: DO NOT KNIT WITH KNIT BUTTON. INSTEAD USE THIS:\n     rmarkdown::render('README.Rmd', output_format = 'github_document', output_file = 'README.md') \n--\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  #out.width = \"100%\",\n  fig.path = \"images/\"\n)\nis_online = curl::has_internet()\n```\n\n# An Introduction to Spatial Data Analysis and Statistics: A Course in R\n\n\u003c!-- badges: start --\u003e\n  [![GitHub all contributors](https://img.shields.io/github/contributors/paezha/spatial-analysis-r?color=2b9348)](https://github.com/paezha/spatial-analysis-r/graphs/contributors)\n  [![GitHub commit activity](https://img.shields.io/github/commit-activity/y/paezha/spatial-analysis-r)\n  [![Launch Rstudio Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/paezha/spatial-analysis-r/main?urlpath=rstudio)\n  [![DOI](https://zenodo.org/badge/391072865.svg)](https://zenodo.org/badge/latestdoi/391072865)\n\u003c!-- badges: end --\u003e\n\n## Introduction\n\nThis repository hosts the code underlying the book *An Introduction to Spatial Data Analysis and Statistics: A Course in R*, by [Antonio Paez](https://www.science.mcmaster.ca/ees/component/comprofiler/userprofile/paezha.html):\n\n\u003e Paez A (2021). An Introduction to Spatial Data Analysis and Statistics: A Course in R. McMaster Invisible Press. ISBN: 978-1-7778515-0-7 \n\nThe book is free to read online at https://paezha.github.io/spatial-analysis-r.\n\n## Resources for Students and Instructors\n\n### Presentation slides\n\nI have created a set of presentation slides in mentimeter for each substantive chapter in the book. I use these as mini-lectures in a [flipped classroom](https://en.wikipedia.org/wiki/Flipped_classroom) format in my course, but they can be used as a template for creating longer presentations or lectures.\n\nChapter | Mentimeter Slides | Static pdf file\n--------|-------------------|----------------\nChapter 3 | [Introduction to Mapping](https://www.mentimeter.com/s/de73cd678c3af6b487f2f06eee44cad7/966186ab94da/edit) | pdf\nChapter 5 | [Mapping in `R` Continued](https://www.mentimeter.com/s/0fbd2c03bf23a9da5fbac902278644fe/ee9058215205/edit) | pdf\nChapter 7 | [Maps as Processes](https://www.mentimeter.com/s/59484637c743e96b6810c5e48b2cf405/d1152a9e811c/edit) | pdf\nChapter 9 | [Point Pattern Analysis I](https://www.mentimeter.com/s/2db531a235490f7d66a0077f2c4f0930/df1cd6ccccbb/edit) | pdf\nChapter 11 | [Point Pattern Analysis II](https://www.mentimeter.com/s/100f17f481ed1f28dd98112492533ba6/389b8ed12832/edit) | pdf\nChapter 13 | [Point Pattern Analysis III](https://www.mentimeter.com/s/8495ddf8551f0083017726a9f68cfa5b/4e5c29e8c78e/edit) | pdf\nChapter 15 | [Point Pattern Analysis IV](https://www.mentimeter.com/s/587258400bd04521b52585f27296a799/57f84401a6a6/edit) | pdf\nChapter 17 | [Point Pattern Analysis V](https://www.mentimeter.com/s/fe385c8dbd256f2645507290f579b15c/2056e80d53e4/edit) | pdf\nChapter 19 | [Area Data I](https://www.mentimeter.com/s/cab8fcae7e9b2cd1f447f79b5349dd23/d939ca4b33e9/edit) | pdf\nChapter 21 | [Area Data II](https://www.mentimeter.com/s/c8442809151f00d4ac7e4a300bdf707a/20932ed527b6/edit) | pdf\nChapter 23 | [Area Data III](https://www.mentimeter.com/s/175ee004df6fb9452837023e02b2960b/96666c58d803/edit) | pdf\nChapter 25 | [Area Data IV](https://www.mentimeter.com/s/516dae79f2558cd948da3de61b1c2b54/b7bb868b80d0/edit) | pdf\nChapter 27 | [Area Data V](https://www.mentimeter.com/s/32ee96ef3aaf83559b779f3fb88fc209/341e94b74b69/edit) | pdf\nChapter 29 | [Area Data VI](https://www.mentimeter.com/s/13eade97c82235b94c73d6dec6ef34a7/10a4634c3a9d/edit) | pdf\nChapter 31 | [Spatially Continuous Data I](https://www.mentimeter.com/s/57b95c57c9a4b75e91d91adb8b6e5faa/330c2ca0d567/edit) | pdf\nChapter 33 | [Spatially Continuous Data II](https://www.mentimeter.com/s/b40aa86207d96711a40c73397bd36d08/f8248b9e8ecd/edit) | pdf\nChapter 35 | [Spatially Continuous Data III](https://www.mentimeter.com/s/d651523809c79353767df82bc7ba4d2f/d8e42a7811ed/edit) | pdf\nChapter 37 | [Spatially Continuous Data IV](https://www.mentimeter.com/s/78b3ec0313be43abe9995fe4c3447dd2/07a125804a15/edit) | pdf\n\n### Template repository for projects\n\nI created a [template repository](https://github.com/paezha/ES4GA3-Sample-Repository) to help students get started with the use of GitHub and R Markdown for collaborative work on term projects. In my own course adoption of this workflow is completely optional. Not every student/group has the inclination/time to adopt this approach, but those who do produce very professional-looking reports and learn valuable skills.\n\n### Examples of projects\n\nThese are examples of projects completed in this course:\n\n- [Examining the Relationships Between Socioeconomic Variables and Particulate Air Pollution in the Toronto Metropolitan Area](https://github.com/paezha/Air-Pollution-Correlates-4GA3)  \n- [Evaluating Effects of Population Demographics on Access to Sexual Health Care: A Toronto Case Study](https://github.com/paezha/Sexual-Health-Clinics-4GA3)  \n- [Investigating Socio-Economic Disparities in the Damages Caused by Hurricane Katrina and Hurricane Rita in Southern Louisiana Counties](https://github.com/paezha/Hurricane-Damage-Lousiana-4GA3)  \n- [The Effects of Income and Unemployment on Crime in Toronto](https://github.com/paezha/Crime-in-Toronto-4GA3)  \n\n## Contributing\n\nAn advantage of an Open Educational Resource compared to traditional publishing (besides it being free!) is that it is a live, ongoing project, for as long as anyone cares for it. If you are using this resource, I would encourage you to contribute to improve it, by:\n\n- suggesting improvements to the text, e.g. clarifying unclear sentences, fixing typos (see guidance from [Yihui Xie](https://yihui.name/en/2013/06/fix-typo-in-documentation/));\n- proposing changes to the code, e.g. to do things in a more efficient way; and\n- making requests to develop content (see the project's [issue tracker](https://github.com/paezha/spatial-analysis-r/issues)).\n\n\u003c!-- Need to check what the style is\nSee [our-style.md](https://github.com/Robinlovelace/geocompr/blob/master/our-style.md) for the book's style.\n\n--\u003e\n\n```{r, include=FALSE}\ncontributors = source(\"code/list-contributors.R\")[[1]]\n# save for future reference:\nreadr::write_csv(contributors, \"extdata/contributors.csv\")\nc_txt = contributors$name\nc_url = contributors$link\nc_rmd = paste0(\"[\", c_txt, \"](\", c_url, \")\")\ncontributors_text = paste0(c_rmd, collapse = \", \")\n```\n\nMany thanks to all contributors to the book so far via GitHub (this list will update automatically): `r contributors_text`.\n\n\u003c!-- Need to figure out what this is\nDuring the project we aim to contribute 'upstream' to the packages that make geocomputation with R possible.\nThis impact is recorded in [`our-impact.csv`](https://github.com/Robinlovelace/geocompr/blob/master/our-impact.csv).\n--\u003e\n\n\u003c!--\n## Reproducing the book\n\nTo ease reproducibility, we created the `geocompkg` package.\nInstalling it from GitHub will install all the R packages needed build the book (you will a computer with necessary [system dependencies](https://github.com/r-spatial/sf#installing) and the [**remotes**](https://github.com/r-lib/remotes/) package installed):\n\n\n```{r, eval=FALSE, message=FALSE}\ninstall.packages(\"remotes\")\nremotes::install_github(\"geocompr/geocompkg\")\n```\n\nYou need a recent version of the GDAL, GEOS, PROJ and UDUNITS libraries installed for this to work on Mac and Linux. See the **sf** package's [README](https://github.com/r-spatial/sf) for information on that.\n\nOnce the dependencies have been installed you should be able to build and view a local version the book with:\n\n```{r, eval=FALSE}\nbookdown::render_book(\"index.Rmd\") # to build the book\nbrowseURL(\"_book/index.html\") # to view it\n```\n\n\u003c!-- The code associated with each chapter is saved in the `code/chapters/` folder. --\u003e\n\u003c!-- `source(\"code/chapters/07-transport.R\")` runs run the code chunks in chapter 7, for example. --\u003e\n\u003c!-- These R scripts are generated with the follow command which wraps `knitr::purl()`: --\u003e\n\n```{r gen-code, results='hide', echo=FALSE}\n# geocompkg:::generate_chapter_code()\n```\n\n\u003c!--\n## The book in binder\n\nI think I got the binder to work.\n\n[![Launch Rstudio Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/paezha/spatial-analysis-r/main?urlpath=rstudio)\n\nFor many people the quickest way to get started with Geocomputation with R is in your web browser via Binder.\nTo see an interactive RStudio Server instance click on the following button, which will open [mybinder.org](https://mybinder.org/v2/gh/robinlovelace/geocompr/master?urlpath=rstudio) with an R installation that has all the dependencies needed to reproduce the book:\n\n#You can also have a play with the repo in RStudio Cloud by clicking on this link (requires log-in):\n\n\n## The book in a Docker container\n\nTODO\n\u003c!--\nTo ease reproducibility we have made Docker images available, at [geocompr/geocompr](https://hub.docker.com/r/geocompr/geocompr/) on DockerHub.\nThese images allow you to explore Geocomputation with R in a virtual machine that has up-to-date dependencies.\n\nAfter you have [installed docker](https://www.docker.com/community-edition#/download) and set-it up on [your computer](https://docs.docker.com/install/linux/linux-postinstall/) you can start RStudio Server without a password (see the [Rocker project](https://www.rocker-project.org/use/managing_users/) for info on how to add a password and other security steps for public-facing servers):\n\n```sh\ndocker run -p 8787:8787 -e DISABLE_AUTH=TRUE geocompr/geocompr\n```\n\nIf it worked you should be able to open-up RStudio server by opening a browser and navigating to\nhttp://localhost:8787/ resulting in an up-to-date version of R and RStudio running in a container.\n\nStart a plain R session running:\n\n```sh\ndocker run -it geocompr/geocompr R\n```\n\nSee the [geocompr/docker](https://github.com/geocompr/docker#geocomputation-with-r-in-docker) repo for details, including how to share volumes between your computer and the Docker image, for using geographic R packages on your own data and for information on available tags.\n\n## Reproducing this README\n\nTODO\n\n\u003c!--\n\nTo reduce the book's dependencies, scripts to be run infrequently to generate input for the book are run on creation of this README.\n\nThe additional packages required for this can be installed as follows:\n\n```{r extra-pkgs, message=FALSE, eval=FALSE}\nsource(\"code/extra-pkgs.R\")\n```\n\nWith these additional dependencies installed, you should be able to run the following scripts, which create content for the book, that we've removed from the main book build to reduce package dependencies and the book's build time:\n\n```{r source-readme, eval=FALSE}\nsource(\"code/cranlogs.R\")\nsource(\"code/sf-revdep.R\")\nsource(\"code/08-urban-animation.R\")\nsource(\"code/08-map-pkgs.R\")\n```\n\nNote: the `.Rproj` file is configured to build a website not a single page.\nTo reproduce this [README](https://github.com/Robinlovelace/geocompr/blob/master/README.Rmd) use the following command:\n\n```{r render-book, eval=FALSE}\nrmarkdown::render(\"README.Rmd\", output_format = \"github_document\", output_file = \"README.md\")\n```\n\n\n```{r, eval=FALSE, echo=FALSE}\n# We aim to make every script in the `code` folder reproducible.\n# To check they can all be reproduced run the following:\n# Aim: test reproducibility of scripts\nscript_names = list.files(\"code\", full.names = T)\navoid = \"pkgs|anim|us|saga|sliver|tsp|parti|polycent|cv|svm|data|location|eco|rf|cran|hex\"\ndontrun = grepl(avoid, script_names)\nscript_names = script_names[!dontrun]\ncounter = 0\nfor(i in script_names[45:length(script_names)]) {\n  counter = counter + 1\n  print(paste0(\"Script number \", counter, \": \", i))\n  source(i)\n}\n```\n\n\n\u003c!-- ## Book statistics --\u003e\n\n\u003c!-- An indication of the book's progress over time is illustrated below (to be updated roughly every week as the book progresses). --\u003e\n\n\u003c!--\n\n\n```{r gen-stats, echo=FALSE, message=FALSE, warning=FALSE, eval=FALSE}\n# source(\"code/generate-chapter-code.R\")\nbook_stats = readr::read_csv(\"extdata/word-count-time.csv\",\n                             col_types=('iiDd'))\n# to prevent excessive chapter count\nif(Sys.Date() \u003e max(book_stats$date) + 5) {\n  book_stats_new = geocompkg:::generate_book_stats()\n  book_stats = bind_rows(book_stats, book_stats_new)\n  readr::write_csv(book_stats, \"extdata/word-count-time.csv\")\n}\nbook_stats = dplyr::filter(book_stats, chapter \u003c= 15) \nlibrary(ggplot2)\nbook_stats$chapter = formatC(book_stats$chapter, width = 2, format = \"d\", flag = \"0\")\nbook_stats$chapter = fct_rev(as.factor(book_stats$chapter))\nbook_stats$n_pages = book_stats$n_words / 300\n```\n\n```{r bookstats, warning=FALSE, echo=FALSE, fig.width=8, fig.height=5, eval=FALSE}\nggplot(book_stats) +\n  geom_area(aes(date, n_pages, fill = chapter), position = \"stack\") +\n  ylab(\"Estimated number of pages\") +\n  xlab(\"Date\") + \n  scale_x_date(date_breaks = \"2 month\",\n               limits = c(min(book_stats$date), as.Date(\"2018-10-01\")),\n               date_labels = \"%b %Y\") +\n  coord_cartesian(ylim = c(0, 350))\n```\n\n\u003c!-- Book statistics: estimated number of pages per chapter over time. --\u003e\n\n\u003c!--\n## Citations\n--\u003e\n\n\u003c!--\nTODO\n\nTo cite packages used in this book we use code from [Efficient R Programming](https://csgillespie.github.io/efficientR/):\n\n```{r gen-cite, warning=FALSE}\n# geocompkg:::generate_citations()\n```\n\nThis generates .bib and .csv files containing the packages.\nThe current of packages used can be read-in as follows:\n\n```{r pkg_df, message=FALSE}\n#pkg_df = readr::read_csv(\"extdata/package_list.csv\")\n```\n\nOther citations are stored online using Zotero.\n\nIf you would like to add to the references, please use Zotero, join the [open group](https://www.zotero.org/groups/418217/energy-and-transport) add your citation to the open [geocompr library](https://www.zotero.org/groups/418217/energy-and-transport/items/collectionKey/9K6FRP6N).\n\nWe use the following citation key format:\n\n```\n[auth:lower]_[veryshorttitle:lower]_[year]\n```\n\nThis can be set from inside Zotero desktop with the Better Bibtex plugin installed (see [github.com/retorquere/zotero-better-bibtex](https://github.com/retorquere/zotero-better-bibtex)) by selecting the following menu options (with the shortcut `Alt+E` followed by `N`), and as illustrated in the figure below:\n\n```\nEdit \u003e Preferences \u003e Better Bibtex\n```\n\n![](figures/zotero-settings.png)\n\nZotero settings: these are useful if you want to add references.\n\nWe use Zotero because it is a powerful open source reference manager that integrates well with the **citr** package.\nAs described in the GitHub repo [Robinlovelace/rmarkdown-citr-demo](https://github.com/Robinlovelace/rmarkdown-citr-demo).\n\n## References\n\n```{r}\n# remotes::install_github(\"gadenbuie/regexplain\")\n# regexplain::regexplain_file(\"extdata/package_list.csv\")\n#pattern = \" \\\\[[^\\\\}]*\\\\]\" # perl=TRUE\n#pkg_df$Title = gsub(pattern = pattern, replacement = \"\", x = pkg_df$Title, perl = TRUE)\n#knitr::kable(pkg_df)\n```\n\n--\u003e\n","funding_links":[],"categories":["HTML"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaezha%2Fspatial-analysis-r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaezha%2Fspatial-analysis-r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaezha%2Fspatial-analysis-r/lists"}