Skip to content

Commit

Permalink
artistry
Browse files Browse the repository at this point in the history
  • Loading branch information
wokech committed Dec 9, 2023
1 parent ecf311f commit 452c63a
Show file tree
Hide file tree
Showing 99 changed files with 10,993 additions and 7 deletions.
16 changes: 16 additions & 0 deletions _freeze/posts/r_tistry/aRt_1/aRt_eac_1/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hash": "fa5cb640ed398cefaffbf48541922818",
"result": {
"markdown": "---\ntitle: \"R-tistry (Part 1)\"\nsubtitle: \"Using ggforce and geom_voronoi_tile() to generate Voronoi diagrams depicting the flags of the East African Community\"\nauthor: \"William Okech\"\ndate: \"2023-12-02\"\nimage: \"r_tistry.png\"\ncategories: [RStudio, R, Tutorial, Blog, R-tistry]\ntoc: true\nformat: \n html:\n code-fold: show\n code-overflow: wrap\n warning: false\n---\n\n\n# Introduction\n\nThe East African Community is a regional intergovernmental organization comprising eight (8) partner states, namely: Kenya, Tanzania, Uganda, Burundi, Rwanda, South Sudan, Democratic Republic of the Congo, and, most recently, Somalia. Kenya, Tanzania, and Uganda were the founding members in 1967 before the organization dissolved in 1977. The organization was re-established in the year 2000, and new members were accepted in subsequent years: Burundi and Rwanda (2009), South Sudan (2016), Democratic Republic of the Congo (2022), and Somalia (2023).\n\nIn this post, I will use ggforce and geom_voronoi_tile() to generate Voronoi diagrams depicting the flags of the East African Community.\n\nThis work is inspired by Albert Rapp's [blog post](https://albert-rapp.de/posts/ggplot2-tips/05_ggforce_examples/05_ggforce_examples), where he provides examples of the use of ggforce.\n\n# Section 1: Load all the required libraries\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\n#install.packages(\"ggforce\")\nlibrary(ggforce)\nlibrary (patchwork)\n```\n:::\n\n\n# Section 2: General equations for generating the voronoi plots\n\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(23479) # set a random seed for pseudorandom number generator\nN <- 1000\nvoronoi_1 <- tibble(x = runif(N), y = runif(N)) %>% # create a dataset\n ggplot(aes(x, y)) + \n geom_voronoi_tile(aes(fill = y)) # generate the voronoi plot\n```\n:::\n\n\n# Section 3: Sample voronoi image\n\nGenerated by [Albert Rapp](https://albert-rapp.de/posts/ggplot2-tips/05_ggforce_examples/05_ggforce_examples)\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvoronoi_1 +\n scale_fill_viridis_c(option = 'A') +\n theme_void() + \n theme(legend.position = 'none')\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-3-1.png){width=672}\n:::\n:::\n\n\nThe option in scale_fill_viridis_c() can be set between 'A' and 'H' and or it can be either \"magma\", \"inferno\", \"plasma\", \"viridis\", \"cividis\", \"rocket\", \"mako\", or \"turbo.\"\n\nThe [viridis scales](https://ggplot2.tidyverse.org/reference/scale_viridis.html#ref-examples) provide colour maps that are perceptually uniform in both colour and black-and-white. They are also designed to be perceived by viewers with common forms of colour blindness.\n\n# Section 4: Flags of the East African Community and Individual Countries\n\n## a) Kenya\n\n\n::: {.cell}\n\n```{.r .cell-code}\nken_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#006600\", \"#FFFFFF\", \"#BB0000\", \"#FFFFFF\", \"#000000\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Kenya\")\nken_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-4-1.png){width=672}\n:::\n:::\n\n\n## b) Tanzania\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntan_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#00A3DD\", \"#FBD016\", \"#000000\", \"#FBD016\",\"#1EB53A\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Tanzania\")\ntan_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-5-1.png){width=672}\n:::\n:::\n\n\n## c) Uganda\n\n\n::: {.cell}\n\n```{.r .cell-code}\nuga_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#D90000\", \"#FCDC04\", \"#000000\", \"#FFFFFF\", \"#D90000\", \"#FCDC04\", \"#000000\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Uganda\")\nuga_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-6-1.png){width=672}\n:::\n:::\n\n\n## d) Burundi\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbur_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#CE1126\", \"#1EB53A\", \"#FFFFFF\", \"#1EB53A\", \"#CE1126\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Burundi\")\nbur_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-7-1.png){width=672}\n:::\n:::\n\n\n## e) Rwanda\n\n\n::: {.cell}\n\n```{.r .cell-code}\nrwa_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#20603D\", \"#FAD201\", \"#00A1DE\", \"#00A1DE\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Rwanda\")\nrwa_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-8-1.png){width=672}\n:::\n:::\n\n\n## f) South Sudan\n\n\n::: {.cell}\n\n```{.r .cell-code}\nssud_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#078930\", \"#FFFFFF\", \"#DA121A\", \"#0F47AF\", \"#000000\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"South Sudan\")\nssud_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-9-1.png){width=672}\n:::\n:::\n\n\n## g) Democratic Republic of the Congo\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndrc_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#007FFF\", \"#F7D518\", \"#CE1021\", \"#F7D518\", \"#007FFF\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Democratic Republic of Congo\")\ndrc_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-10-1.png){width=672}\n:::\n:::\n\n\n## h) Somalia\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsom_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#418FDE\", \"#FFFFFF\", \"#418FDE\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Somalia\")\nsom_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-11-1.png){width=672}\n:::\n:::\n\n\n## i) East African Community\n\n\n::: {.cell}\n\n```{.r .cell-code}\neac <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#418FDE\", \"#FFFFFF\", \"#D90000\", \"#006600\",\"#FBD016\", \"#006600\", \"#000000\", \"#FFFFFF\", \"#418FDE\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"East African Community\")\neac\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-12-1.png){width=672}\n:::\n:::\n\n\n# Conclusion\n\nThe goal of this post was to demonstrate that one can use code to generate art. Here, the packages, ggplot2 and ggforce, available in R/RStudio, were used to generate Voronoi diagrams (depicting the flags of East Africa) with geom_voronoi_tile(). To compare the generated diagrams with the original flags look at the Flags of the World page on [Worldometer](https://www.worldometers.info/geography/flags-of-the-world/)\n\n# Assignment\n\nTry and generate your own Voronoi diagram (preferably the flag of your home country or country of residence), save with ggsave() using the correct dimensions and dpi, and the share on social media #aRt\n",
"supporting": [
"aRt_eac_1_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions _freeze/posts/r_tistry/aRt_2/aRt_eac_2/execute-results/html.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions _freeze/posts/r_tistry/aRt_eac_1/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hash": "2c8254fdea3aa91e6ae4ebfaddb83527",
"result": {
"markdown": "---\ntitle: \"R-tistry (Part 1)\"\nsubtitle: \"Using ggforce and geom_voronoi_tile() to generate Voronoi diagrams depicting the flags of the East African Community\"\nauthor: \"William Okech\"\ndate: \"2023-12-02\"\nimage: \"\"\ncategories: [RStudio, R, Tutorial, Blog, R-tistry]\ntoc: true\nformat: \n html:\n code-fold: show\n code-overflow: wrap\n warning: false\n---\n\n\n# Introduction\n\nThe East African Community is a regional intergovernmental organization comprising eight (8) partner states, namely: Kenya, Tanzania, Uganda, Burundi, Rwanda, South Sudan, Democratic Republic of the Congo, and, most recently, Somalia. Kenya, Tanzania, and Uganda were the founding members in 1967 before the organization dissolved in 1977. The organization was re-established in the year 2000, and new members were accepted in subsequent years: Burundi and Rwanda (2009), South Sudan (2016), Democratic Republic of the Congo (2022), and Somalia (2023).\n\nIn this post, I will use ggforce and geom_voronoi_tile() to generate Voronoi diagrams depicting the flags of the East African Community.\n\nThis work is inspired by Albert Rapp's [blog post](https://albert-rapp.de/posts/ggplot2-tips/05_ggforce_examples/05_ggforce_examples), where he provides examples of the use of ggforce.\n\n# Section 1: Load all the required libraries\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\n#install.packages(\"ggforce\")\nlibrary(ggforce)\nlibrary (patchwork)\n```\n:::\n\n\n# Section 2: General equations for generating the voronoi plots\n\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(23479) # set a random seed for pseudorandom number generator\nN <- 1000\nvoronoi_1 <- tibble(x = runif(N), y = runif(N)) %>% # create a dataset\n ggplot(aes(x, y)) + \n geom_voronoi_tile(aes(fill = y)) # generate the voronoi plot\n```\n:::\n\n\n# Section 3: Sample voronoi image\n\nGenerated by [Albert Rapp](https://albert-rapp.de/posts/ggplot2-tips/05_ggforce_examples/05_ggforce_examples)\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvoronoi_1 +\n scale_fill_viridis_c(option = 'A') +\n theme_void() + \n theme(legend.position = 'none')\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-3-1.png){width=672}\n:::\n:::\n\n\nThe option in scale_fill_viridis_c() can be set between 'A' and 'H' and or it can be either \"magma\", \"inferno\", \"plasma\", \"viridis\", \"cividis\", \"rocket\", \"mako\", or \"turbo.\"\n\nThe [viridis scales](https://ggplot2.tidyverse.org/reference/scale_viridis.html#ref-examples) provide colour maps that are perceptually uniform in both colour and black-and-white. They are also designed to be perceived by viewers with common forms of colour blindness.\n\n# Section 4: Flags of the East African Community and Individual Countries\n\n## a) Kenya\n\n\n::: {.cell}\n\n```{.r .cell-code}\nken_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#006600\", \"#FFFFFF\", \"#BB0000\", \"#FFFFFF\", \"#000000\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Kenya\")\nken_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-4-1.png){width=672}\n:::\n:::\n\n\n## b) Tanzania\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntan_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#00A3DD\", \"#FBD016\", \"#000000\", \"#FBD016\",\"#1EB53A\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Tanzania\")\ntan_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-5-1.png){width=672}\n:::\n:::\n\n\n## c) Uganda\n\n\n::: {.cell}\n\n```{.r .cell-code}\nuga_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#D90000\", \"#FCDC04\", \"#000000\", \"#FFFFFF\", \"#D90000\", \"#FCDC04\", \"#000000\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Uganda\")\nuga_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-6-1.png){width=672}\n:::\n:::\n\n\n## d) Burundi\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbur_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#CE1126\", \"#1EB53A\", \"#FFFFFF\", \"#1EB53A\", \"#CE1126\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Burundi\")\nbur_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-7-1.png){width=672}\n:::\n:::\n\n\n## e) Rwanda\n\n\n::: {.cell}\n\n```{.r .cell-code}\nrwa_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#20603D\", \"#FAD201\", \"#00A1DE\", \"#00A1DE\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Rwanda\")\nrwa_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-8-1.png){width=672}\n:::\n:::\n\n\n## f) South Sudan\n\n\n::: {.cell}\n\n```{.r .cell-code}\nssud_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#078930\", \"#FFFFFF\", \"#DA121A\", \"#0F47AF\", \"#000000\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"South Sudan\")\nssud_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-9-1.png){width=672}\n:::\n:::\n\n\n## g) Democratic Republic of the Congo\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndrc_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#007FFF\", \"#F7D518\", \"#CE1021\", \"#F7D518\", \"#007FFF\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Democratic Republic of Congo\")\ndrc_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-10-1.png){width=672}\n:::\n:::\n\n\n## h) Somalia\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsom_1 <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#418FDE\", \"#FFFFFF\", \"#418FDE\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"Somalia\")\nsom_1\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-11-1.png){width=672}\n:::\n:::\n\n\n## i) East African Community\n\n\n::: {.cell}\n\n```{.r .cell-code}\neac <- voronoi_1 +\n scale_fill_gradientn(colours = c(\"#418FDE\", \"#FFFFFF\", \"#D90000\", \"#006600\",\"#FBD016\", \"#006600\", \"#000000\", \"#FFFFFF\", \"#418FDE\")) +\n theme_void() + \n theme(legend.position = 'none',\n plot.title = element_text(size = 12, hjust = 0.5)) +\n labs(title = \"East African Community\")\neac\n```\n\n::: {.cell-output-display}\n![](aRt_eac_1_files/figure-html/unnamed-chunk-12-1.png){width=672}\n:::\n:::\n\n\n# Conclusion\n\nThe goal of this post was to demonstrate that one can use code to generate art. Here, the packages, ggplot2 and ggforce, available in R/RStudio, were used to generate Voronoi diagrams (depicting the flags of East Africa) with geom_voronoi_tile(). To compare the generated diagrams with the original flags look at the Flags of the World page on [Worldometer](https://www.worldometers.info/geography/flags-of-the-world/)\n\n# Assignment\n\nTry and generate your own Voronoi diagram (preferably the flag of your home country or country of residence), save with ggsave() using the correct dimensions and dpi, and the share on social media #aRt\n",
"supporting": [
"aRt_eac_1_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions _freeze/posts/r_tistry/aRt_eac_2/execute-results/html.json

Large diffs are not rendered by default.

Loading

0 comments on commit 452c63a

Please sign in to comment.