Skip to content

Commit

Permalink
full-width visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
ikashnitsky committed Nov 6, 2023
1 parent e1d42e7 commit f8b0cf2
Show file tree
Hide file tree
Showing 25 changed files with 252 additions and 239 deletions.
14 changes: 12 additions & 2 deletions 2018/ddd-poster/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ categories: [r, tricolore, rspatial]
---

***

```{r, include=FALSE}
knitr::opts_chunk$set(
message = FALSE, warning = FALSE
)
```


On 28 November 2018 I presented a poster at [Dutch Demography Day][nvd] in Utrecht. Here it is:

![](compare-poster.png)
```{r, echo=FALSE}
#| column: screen-inset
knitr::include_graphics("compare-poster.png")
```




The poster compares population age structures, represented as ternary compositions in three broad age groups, of European NUTS-3 regions and the United States counties. I used ternary color-coding, a dataviz approach that [Jonas Schöley][js] and me recently brought to R in [tricolore][tric] package.

Expand Down
1 change: 1 addition & 0 deletions 2023/geocoding/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ country_borders <- world_outline_robinson %>%
Now everything is ready to map!

```{r, out.width="100%"}
#| column: screen-inset
# map!
world_outline_robinson %>%
filter(!iso_a2 == "AQ") %>% # get rid of Antarctica
Expand Down
1 change: 1 addition & 0 deletions 2023/map-borders/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ geom_sf(data = . %>% ms_innerlines(), color = 2, size = 1)
Finally, let's put the two maps side by side.

```{r, out.width="100%"}
#| column: screen-inset
# put side by side
library(patchwork)
(
Expand Down
14 changes: 14 additions & 0 deletions _freeze/2018/ddd-poster/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"hash": "e17d2e89ac133462522ef69b6489956b",
"result": {
"markdown": "---\ntitle: \"Compare population age structures of Europe NUTS-3 regions and the US counties using ternary color-coding\"\ndescription-meta: \"{{< meta website.description >}}\"\ndate: \"2018-12-03\"\nimage: teaser.png\ncategories: [r, tricolore, rspatial]\n---\n\n\n***\n\n\n\n\n\nOn 28 November 2018 I presented a poster at [Dutch Demography Day][nvd] in Utrecht. Here it is:\n\n\n::: {.cell .column-screen-inset}\n::: {.cell-output-display}\n![](compare-poster.png){width=1756}\n:::\n:::\n\n\n\n\n\nThe poster compares population age structures, represented as ternary compositions in three broad age groups, of European NUTS-3 regions and the United States counties. I used ternary color-coding, a dataviz approach that [Jonas Schöley][js] and me recently brought to R in [tricolore][tric] package. \n\nIn these maps, each region's population age composition is uniquely color-coded. Colors show direction and magnitude of deviation from the center point, which represents the average age composition. Hue component of a color encodes the direction of deviation: towards yellow – more elderly population (65+); cyan – more people at working ages (15–64); magenta–more kids (<15).\n\nOf course, NUTS-3 regions and the US counties are not perfect to compare; on average, NUTS-3 regions are roughly ten times bigger. That's why the colors for European regions look quite muted, they are closer to the grey average composition.\n\n\nThe poster won [NVD][nvd] Poster Award via online voting of the conference participants.\n\n![](poster-award.png)\n\n***\n\n::: {.callout-tip}\n# Replication \nThis time I layouted the poster in [Inkscape][ink] rather than arranging everything with hundreds of R code lines. But all the elements of the posted are reproducible with code from [this github repo][repo].\n:::\n\n\n::: {.callout-note}\n# See also\n - [Kashnitsky, I., & Schöley, J. (2018). Regional population structures at a glance. _The Lancet_, 392(10143), 209–210.][tl]\n - [My PhD project -- Regional demographic convergence in Europe][proj]\n - [Paper (Schöley & Willekens 2017) with the initial ideas for tricolore package][demres17]\n - [An example of ternary colorcoding used to visualize cause-of-death data][dr18]\n:::\n\n\n[nvd]: http://www.nvdemografie.nl/en/activities/dutch-demography-day/dutch-demography-day-2018\n[js]: https://twitter.com/jschoeley\n[tric]: https://cran.r-project.org/web/packages/tricolore/index.html\n[ink]: https://inkscape.org\n[repo]: https://github.com/ikashnitsky/compare-pop-eu-us\n\n[tl]: https://doi.org/10.1186/s41118-017-0018-2\n[proj]: https://osf.io/d4hjx/\n[demres17]: https://doi.org/10.4054/DemRes.2017.36.21\n[dr18]: https://github.com/ikashnitsky/demres-2018-geofacet\n\n\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
4 changes: 2 additions & 2 deletions _freeze/2023/geocoding/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"hash": "fb5201083e4ee7c55f1e3e97d3f37733",
"hash": "0170d8413e3b1b1de6af5736c184048b",
"result": {
"markdown": "---\ntitle: \"Geocode address text strings using `tidygeocoder`\"\ndescription-meta: \"{{< meta website.description >}}\"\ndate: \"2023-11-01\"\nimage: teaser.png\ncategories: [r, geocoding, rspatial, ggplot2]\n---\n\n\n\n\n***\n\nDeriving coordinates from a string of text that represents a physical location on Earth is a common geo data processing task. A usual use case would be an address question in a survey. There is a way to automate queries to a special GIS service so that it takes a text string as an input and returns the geographic coordinates. This used to be quite a challenging task since it required obtaining an API access to the GIS service like Google Maps. Things changed radically with the appearance of `tidygeocoder` that queries the free Open Street Map. \n\nIn this tiny example I'm using the birth places that students of my [2022 BSSD dataviz course][bssd] kindly contributed. In the class I asked students to fill a Google Form consisting of just two fields -- city and country of birth. The resulting small dataset is [here][data]\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\nlibrary(sf)\n\n# download the data\n# https://stackoverflow.com/a/28986107/4638884\nlibrary(gsheet)\n\nraw <- gsheet2tbl(\"https://docs.google.com/spreadsheets/d/1YlfLQc_aOOiTqaSGu5TI70OQy1ewTa_Ti0qAEOEcy58\")\n\n# clean a bit and join both fields in one text string \ndf <- raw %>% \n janitor::clean_names() %>% \n drop_na() %>% \n mutate(text_to_geocode = paste(city_settlement, country, sep = \", \"))\n```\n:::\n\n\nNow we are ready to unleash the power of `tidygeocoder`. The way the main unction in the package works is very similar to `mutate` -- you just specify which column of the dataset contains the text string to geocode, and it return the geographic coordinates. \n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidygeocoder)\n\ndf_geocoded <- df %>% \n geocode(text_to_geocode, method = \"osm\")\n```\n:::\n\n\nThe magic has already happened. The rest is just the routines to drop the points on the map. Yes, I am submitting this as my first 2023 entry to the [`#30DayMapChallenge`][30d] =)\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# convert coordinates to an sf object\ndf_plot <- df_geocoded %>% \n drop_na() %>% \n st_as_sf(\n coords = c(\"long\", \"lat\"),\n crs = 4326\n )\n```\n:::\n\n\nNext are several steps to plot countries of the worlds as the background map layer. Note that I'm using the trick of producing a separate lines layer for the country borders, there is a [separate post][borders] about this small dataviz trick.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# get world map outline (you might need to install the package)\nworld_outline <- spData::world %>% \n st_as_sf()\n\n# let's use a fancy projection\nworld_outline_robinson <- world_outline %>% \n st_transform(crs = \"ESRI:54030\")\n\ncountry_borders <- world_outline_robinson %>% \n rmapshaper::ms_innerlines()\n```\n:::\n\n\nNow everything is ready to map!\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# map!\nworld_outline_robinson %>% \n filter(!iso_a2 == \"AQ\") %>% # get rid of Antarctica\n ggplot()+\n geom_sf(fill = \"#269999\", color = NA)+\n geom_sf(data = country_borders, size = .25, color = \"#269999\" %>% prismatic::clr_lighten())+\n geom_sf(\n data = df_plot, fill = \"#dafa26\", \n color = \"#dafa26\" %>% prismatic::clr_darken(),\n size = 1.5, shape = 21\n )+\n coord_sf(datum = NA)+\n theme_minimal(base_family = \"Atkinson Hyperlegible\")+\n labs(\n title = \"Birth places of the participants\",\n subtitle = \"Barcelona Summer School of Demography dataviz course at CED, July 2022\",\n caption = \"@ikashnitsky.phd\"\n )+\n theme(\n text = element_text(color = \"#ccffff\"),\n plot.background = element_rect(fill = \"#042222\", color = NA),\n axis.text = element_blank(),\n plot.title = element_text(face = 2, size = 18, color = \"#ccffff\")\n )\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-6-1.png){width=100%}\n:::\n:::\n\n\n\nThat's it. Going from text to point on the map has never been easier. \n\n\n***\n\n::: {.callout-note}\n# This post is one in the **dataviz course series**. Other posts:\n- [The easiest way to radically improve map aesthetics][borders]\n- [Show all data in the background of your faceted ggplot][bg]\n- [Dotplot – the single most useful yet largely neglected dataviz type][dotplot]\n- [Save space in faceted plots][shrink]\n:::\n\n\n[bssd]: https://github.com/ikashnitsky/dataviz-bssd/releases/tag/v.3.0\n[borders]: https://ikashnitsky.phd/2023/map-borders/\n[bg]: https://ikashnitsky.phd/2020/background-data/\n[dotplot]: https://ikashnitsky.phd/2019/dotplot/\n[data]: https://docs.google.com/spreadsheets/d/1YlfLQc_aOOiTqaSGu5TI70OQy1ewTa_Ti0qAEOEcy58\n[30d]: https://30daymapchallenge.com\n[shrink]: https://ikashnitsky.phd/2023/shrink-space/\n",
"markdown": "---\ntitle: \"Geocode address text strings using `tidygeocoder`\"\ndescription-meta: \"{{< meta website.description >}}\"\ndate: \"2023-11-01\"\nimage: teaser.png\ncategories: [r, geocoding, rspatial, ggplot2]\n---\n\n\n\n\n***\n\nDeriving coordinates from a string of text that represents a physical location on Earth is a common geo data processing task. A usual use case would be an address question in a survey. There is a way to automate queries to a special GIS service so that it takes a text string as an input and returns the geographic coordinates. This used to be quite a challenging task since it required obtaining an API access to the GIS service like Google Maps. Things changed radically with the appearance of `tidygeocoder` that queries the free Open Street Map. \n\nIn this tiny example I'm using the birth places that students of my [2022 BSSD dataviz course][bssd] kindly contributed. In the class I asked students to fill a Google Form consisting of just two fields -- city and country of birth. The resulting small dataset is [here][data]\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\nlibrary(sf)\n\n# download the data\n# https://stackoverflow.com/a/28986107/4638884\nlibrary(gsheet)\n\nraw <- gsheet2tbl(\"https://docs.google.com/spreadsheets/d/1YlfLQc_aOOiTqaSGu5TI70OQy1ewTa_Ti0qAEOEcy58\")\n\n# clean a bit and join both fields in one text string \ndf <- raw %>% \n janitor::clean_names() %>% \n drop_na() %>% \n mutate(text_to_geocode = paste(city_settlement, country, sep = \", \"))\n```\n:::\n\n\nNow we are ready to unleash the power of `tidygeocoder`. The way the main unction in the package works is very similar to `mutate` -- you just specify which column of the dataset contains the text string to geocode, and it return the geographic coordinates. \n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidygeocoder)\n\ndf_geocoded <- df %>% \n geocode(text_to_geocode, method = \"osm\")\n```\n:::\n\n\nThe magic has already happened. The rest is just the routines to drop the points on the map. Yes, I am submitting this as my first 2023 entry to the [`#30DayMapChallenge`][30d] =)\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# convert coordinates to an sf object\ndf_plot <- df_geocoded %>% \n drop_na() %>% \n st_as_sf(\n coords = c(\"long\", \"lat\"),\n crs = 4326\n )\n```\n:::\n\n\nNext are several steps to plot countries of the worlds as the background map layer. Note that I'm using the trick of producing a separate lines layer for the country borders, there is a [separate post][borders] about this small dataviz trick.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# get world map outline (you might need to install the package)\nworld_outline <- spData::world %>% \n st_as_sf()\n\n# let's use a fancy projection\nworld_outline_robinson <- world_outline %>% \n st_transform(crs = \"ESRI:54030\")\n\ncountry_borders <- world_outline_robinson %>% \n rmapshaper::ms_innerlines()\n```\n:::\n\n\nNow everything is ready to map!\n\n\n::: {.cell .column-screen-inset}\n\n```{.r .cell-code}\n# map!\nworld_outline_robinson %>% \n filter(!iso_a2 == \"AQ\") %>% # get rid of Antarctica\n ggplot()+\n geom_sf(fill = \"#269999\", color = NA)+\n geom_sf(data = country_borders, size = .25, color = \"#269999\" %>% prismatic::clr_lighten())+\n geom_sf(\n data = df_plot, fill = \"#dafa26\", \n color = \"#dafa26\" %>% prismatic::clr_darken(),\n size = 1.5, shape = 21\n )+\n coord_sf(datum = NA)+\n theme_minimal(base_family = \"Atkinson Hyperlegible\")+\n labs(\n title = \"Birth places of the participants\",\n subtitle = \"Barcelona Summer School of Demography dataviz course at CED, July 2022\",\n caption = \"@ikashnitsky.phd\"\n )+\n theme(\n text = element_text(color = \"#ccffff\"),\n plot.background = element_rect(fill = \"#042222\", color = NA),\n axis.text = element_blank(),\n plot.title = element_text(face = 2, size = 18, color = \"#ccffff\")\n )\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-6-1.png){width=100%}\n:::\n:::\n\n\n\nThat's it. Going from text to point on the map has never been easier. \n\n\n***\n\n::: {.callout-note}\n# This post is one in the **dataviz course series**. Other posts:\n- [The easiest way to radically improve map aesthetics][borders]\n- [Show all data in the background of your faceted ggplot][bg]\n- [Dotplot – the single most useful yet largely neglected dataviz type][dotplot]\n- [Save space in faceted plots][shrink]\n:::\n\n\n[bssd]: https://github.com/ikashnitsky/dataviz-bssd/releases/tag/v.3.0\n[borders]: https://ikashnitsky.phd/2023/map-borders/\n[bg]: https://ikashnitsky.phd/2020/background-data/\n[dotplot]: https://ikashnitsky.phd/2019/dotplot/\n[data]: https://docs.google.com/spreadsheets/d/1YlfLQc_aOOiTqaSGu5TI70OQy1ewTa_Ti0qAEOEcy58\n[30d]: https://30daymapchallenge.com\n[shrink]: https://ikashnitsky.phd/2023/shrink-space/\n",
"supporting": [
"index_files"
],
Expand Down
Binary file modified _freeze/2023/geocoding/index/figure-html/unnamed-chunk-6-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8b0cf2

Please sign in to comment.