Code
+library(tidyverse)
+#install.packages("ggforce")
+library(ggforce)
+library (patchwork)
diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/execute-results/html.json b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/execute-results/html.json new file mode 100644 index 0000000..a862517 --- /dev/null +++ b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/execute-results/html.json @@ -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{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{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{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{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{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{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{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{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{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{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 + } +} \ No newline at end of file diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-10-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-10-1.png new file mode 100644 index 0000000..d9cf2c5 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-10-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-11-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-11-1.png new file mode 100644 index 0000000..d1a002a Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-11-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-12-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-12-1.png new file mode 100644 index 0000000..e03c2ff Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-12-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-3-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000..126e15b Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-3-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-4-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 0000000..2fde5ec Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-4-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-5-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..cc3e8bb Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-5-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-6-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 0000000..1d95516 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-6-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-7-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 0000000..993e16a Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-7-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-8-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-8-1.png new file mode 100644 index 0000000..2b7eb32 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-8-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-9-1.png b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 0000000..87cc574 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_1/aRt_eac_1/figure-html/unnamed-chunk-9-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/execute-results/html.json b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/execute-results/html.json new file mode 100644 index 0000000..5f23453 --- /dev/null +++ b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/execute-results/html.json @@ -0,0 +1,16 @@ +{ + "hash": "e3fb8bf0c15bcb32a2d92e3563b54790", + "result": { + "markdown": "---\ntitle: \"R-tistry (Part 2)\"\nsubtitle: \"Using geom_segment() to generate images depicting the flags of the East African Community\"\nauthor: \"William Okech\"\ndate: \"2023-12-06\"\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\nIn this post, I will use geom_segment() to generate images depicting the flags of the East African Community.\n\nFor a background of this post, review [Part 1]() of the series.\n\n# Section 1: Load all the required libraries\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse) # collection of packages for preparing, wrangling and visualizing data\nlibrary(ggplot2) # package for data visualization\nlibrary(ggthemes) # ggplot themes\n```\n:::\n\n\n# \\# Section 2: Flags of the East African Community and Individual Countries\n\n## a) Kenya\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2.5), 19), 2.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8), 19), 8))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(10.5), 19), 10.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#FFFFFF\", size = 3.4,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#BB0000\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 3.8,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#006600\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Kenya\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## b) Tanzania\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2.5), 19), 2.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3.5), 19), 3.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9.5), 19), 9.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#1EB53A\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#FBD016\", size = 3.2, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#000000\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FBD016\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#00A3DD\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 10) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Tanzania\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## c) Uganda\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(1.5), 19), 1.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7.5), 19), 7.5))\n\nlines6 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9), 19), 9))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines6, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines5, color = \"#FCDC04\", size = 3.2, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#D90000\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#000000\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FCDC04\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#D90000\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Uganda\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## d) Burundi\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(10), 19), 10))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines3, color = \"#CE1126\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#1EB53A\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Burundi\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## e) Rwanda\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2), 19), 2))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4), 19), 4))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8), 19), 8))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines4, color = \"#00A1DE\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#00A1DE\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FAD201\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#20603D\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Rwanda\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## f) South Sudan\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines00 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(1), 19), 1))\n\nlines0 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2), 19), 2))\n\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(5.5), 19), 5.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8), 19), 8))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9), 19), 9))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(11.5), 19), 11.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#FFFFFF\", size = 4,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#DA121A\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 4,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#078930\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines0, color = \"#0F47AF\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines00, color = \"#FCDD09\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"South Sudan\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## g) Democratic Republic of the Congo\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2.5), 19), 2.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3.5), 19), 3.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9.5), 19), 9.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#007FFF\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#F7D518\", size = 3.2, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#CE1021\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#F7D518\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#007FFF\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 10) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Democratic Republic of the Congo\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## h) Somalia\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(10), 19), 10))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines3, color = \"#418FDE\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#418FDE\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Somalia\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## i) East African Community\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3.5), 19), 3.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(5), 19), 5))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines6 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7.5), 19), 7.5))\n\nlines7 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8.5), 19), 8.5))\n\nlines8 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9), 19), 9))\n\nlines9 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(12), 19), 12))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines9, color = \"#418FDE\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines8, color = \"#FFFFFF\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines7, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines6, color = \"#006600\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines5, color = \"#FBD016\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#006600\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#D90000\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#418FDE\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Somalia\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n# Conclusion\n\nIn this post, ggplot2 and geom_segment(), available in R/RStudio, were used to generate images depicting the flags of East Africa. 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 image, 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_2_files" + ], + "filters": [ + "rmarkdown/pagebreak.lua" + ], + "includes": {}, + "engineDependencies": {}, + "preserve": {}, + "postProcess": true + } +} \ No newline at end of file diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-11-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-11-1.png new file mode 100644 index 0000000..ef56fab Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-11-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-13-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-13-1.png new file mode 100644 index 0000000..31f854d Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-13-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-15-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-15-1.png new file mode 100644 index 0000000..7bab604 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-15-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-17-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-17-1.png new file mode 100644 index 0000000..eafdef5 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-17-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-19-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-19-1.png new file mode 100644 index 0000000..a7f116f Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-19-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-3-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000..173e71a Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-3-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-5-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..6096d76 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-5-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-7-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 0000000..2a5f75f Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-7-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-9-1.png b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 0000000..1f0a843 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_2/aRt_eac_2/figure-html/unnamed-chunk-9-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/execute-results/html.json b/_freeze/posts/r_tistry/aRt_eac_1/execute-results/html.json new file mode 100644 index 0000000..f669b22 --- /dev/null +++ b/_freeze/posts/r_tistry/aRt_eac_1/execute-results/html.json @@ -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{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{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{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{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{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{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{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{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{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{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 + } +} \ No newline at end of file diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-10-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-10-1.png new file mode 100644 index 0000000..d9cf2c5 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-10-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-11-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-11-1.png new file mode 100644 index 0000000..d1a002a Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-11-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-12-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-12-1.png new file mode 100644 index 0000000..e03c2ff Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-12-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-3-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000..126e15b Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-3-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-4-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 0000000..2fde5ec Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-4-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-5-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..cc3e8bb Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-5-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-6-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 0000000..1d95516 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-6-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-7-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 0000000..993e16a Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-7-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-8-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-8-1.png new file mode 100644 index 0000000..2b7eb32 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-8-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-9-1.png b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 0000000..87cc574 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_1/figure-html/unnamed-chunk-9-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/execute-results/html.json b/_freeze/posts/r_tistry/aRt_eac_2/execute-results/html.json new file mode 100644 index 0000000..4633999 --- /dev/null +++ b/_freeze/posts/r_tistry/aRt_eac_2/execute-results/html.json @@ -0,0 +1,16 @@ +{ + "hash": "820d3938fdbb40039e4a8cfae87f91bb", + "result": { + "markdown": "---\ntitle: \"R-tistry (Part 2)\"\nsubtitle: \"Using geom_segment() to generate Voronoi images depicting the flags of the East African Community\"\nauthor: \"William Okech\"\ndate: \"2023-12-06\"\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\nIn this post, I will use geom_segment() to generate images depicting the flags of the East African Community.\n\nFor a background of this post, review [Part 1]() of the series. \n\n# Section 1: Load all the required libraries\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse) # collection of packages for preparing, wrangling and visualizing data\nlibrary(ggplot2) # package for data visualization\nlibrary(ggthemes) # ggplot themes\n```\n:::\n\n\n# # Section 2: Flags of the East African Community and Individual Countries\n\n## a) Kenya\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2.5), 19), 2.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8), 19), 8))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(10.5), 19), 10.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#FFFFFF\", size = 3.4,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#BB0000\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 3.8,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#006600\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Kenya\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## b) Tanzania\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2.5), 19), 2.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3.5), 19), 3.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9.5), 19), 9.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#1EB53A\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#FBD016\", size = 3.2, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#000000\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FBD016\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#00A3DD\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 10) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Tanzania\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## c) Uganda\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(1.5), 19), 1.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7.5), 19), 7.5))\n\nlines6 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9), 19), 9))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines6, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines5, color = \"#FCDC04\", size = 3.2, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#D90000\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#000000\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FCDC04\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#D90000\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Uganda\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## d) Burundi\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(10), 19), 10))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines3, color = \"#CE1126\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#1EB53A\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Burundi\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## e) Rwanda\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2), 19), 2))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4), 19), 4))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8), 19), 8))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines4, color = \"#00A1DE\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#00A1DE\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FAD201\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#20603D\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Rwanda\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## f) South Sudan\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines00 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(1), 19), 1))\n\nlines0 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2), 19), 2))\n\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(5.5), 19), 5.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8), 19), 8))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9), 19), 9))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(11.5), 19), 11.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#FFFFFF\", size = 4,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#DA121A\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 4,lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#078930\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines0, color = \"#0F47AF\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines00, color = \"#FCDD09\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"South Sudan\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## g) Democratic Republic of the Congo\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(2.5), 19), 2.5))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3.5), 19), 3.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9.5), 19), 9.5))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines5, color = \"#007FFF\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#F7D518\", size = 3.2, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#CE1021\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#F7D518\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#007FFF\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 10) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Democratic Republic of the Congo\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## h) Somalia\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(6), 19), 6))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(10), 19), 10))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines3, color = \"#418FDE\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#418FDE\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Somalia\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n## i) East African Community\n\nGenerate the lines required for the plot\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlines1 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3), 19), 3))\n\nlines2 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(3.5), 19), 3.5))\n\nlines3 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(4.5), 19), 4.5))\n\nlines4 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(5), 19), 5))\n\nlines5 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7), 19), 7))\n\nlines6 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(7.5), 19), 7.5))\n\nlines7 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(8.5), 19), 8.5))\n\nlines8 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(9), 19), 9))\n\nlines9 = tibble(\n x = seq(0, 38, by = 2),\n xend=x,\n y=rep(0, 20),\n yend=c(rep(c(12), 19), 12))\n```\n:::\n\n\nPlot the image\n\n\n::: {.cell}\n\n```{.r .cell-code}\nggplot() + \n geom_segment(data=lines9, color = \"#418FDE\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines8, color = \"#FFFFFF\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines7, color = \"#000000\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines6, color = \"#006600\", size = 3, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines5, color = \"#FBD016\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines4, color = \"#006600\", size = 3.4, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) +\n geom_segment(data=lines3, color = \"#D90000\", size = 3.6, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines2, color = \"#FFFFFF\", size = 3.8, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n geom_segment(data=lines1, color = \"#418FDE\", size = 4.0, lineend = \"round\",\n aes(x=x, xend=xend,\n y=y, yend=yend)) + \n ylim(-5, 15) +\n coord_polar() + # allows for the drawing of a polar plot\n labs(title = \"Somalia\") +\n theme(axis.title.x=element_blank(),\n axis.text.x=element_blank(),\n axis.ticks.x=element_blank(),\n axis.title.y=element_blank(),\n axis.text.y=element_blank(),\n axis.ticks.y=element_blank(), \n panel.background = element_rect(fill = \"white\", colour = \"white\"),\n plot.title = element_text(size = 12, hjust = 0.5)) \n```\n\n::: {.cell-output-display}\n{width=672}\n:::\n:::\n\n\n# Conclusion\n\nIn this post, ggplot2 and geom_segment(), available in R/RStudio, were used to generate images depicting the flags of East Africa. 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 image, 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", + "supporting": [ + "aRt_eac_2_files" + ], + "filters": [ + "rmarkdown/pagebreak.lua" + ], + "includes": {}, + "engineDependencies": {}, + "preserve": {}, + "postProcess": true + } +} \ No newline at end of file diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-11-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-11-1.png new file mode 100644 index 0000000..ef56fab Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-11-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-13-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-13-1.png new file mode 100644 index 0000000..31f854d Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-13-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-15-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-15-1.png new file mode 100644 index 0000000..7bab604 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-15-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-17-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-17-1.png new file mode 100644 index 0000000..eafdef5 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-17-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-19-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-19-1.png new file mode 100644 index 0000000..a7f116f Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-19-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-3-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000..173e71a Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-3-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-5-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..6096d76 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-5-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-7-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 0000000..2a5f75f Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-7-1.png differ diff --git a/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-9-1.png b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 0000000..1f0a843 Binary files /dev/null and b/_freeze/posts/r_tistry/aRt_eac_2/figure-html/unnamed-chunk-9-1.png differ diff --git a/_site/blog.html b/_site/blog.html index eb3946e..011e1c8 100644 --- a/_site/blog.html +++ b/_site/blog.html @@ -151,6 +151,34 @@ }) + window.document.addEventListener("DOMContentLoaded", function (_event) { + const listingTargetEl = window.document.querySelector('#listing-posts_r_tistry .list'); + if (!listingTargetEl) { + // No listing discovered, do not attach. + return; + } + + const options = { + valueNames: ['listing-image','listing-date','listing-title','listing-subtitle','listing-author','listing-reading-time','listing-description','listing-categories',{ data: ['index'] },{ data: ['categories'] },{ data: ['listing-date-sort'] },{ data: ['listing-file-modified-sort'] }], + + searchColumns: ["listing-title","listing-author","listing-date","listing-image","listing-description","listing-categories"], + }; + + window['quarto-listings'] = window['quarto-listings'] || {}; + window['quarto-listings']['listing-posts_r_tistry'] = new List('listing-posts_r_tistry', options); + + if (window['quarto-listing-loaded']) { + window['quarto-listing-loaded'](); + } + }); + + window.addEventListener('hashchange',() => { + if (window['quarto-listing-loaded']) { + window['quarto-listing-loaded'](); + } + }) + + window.document.addEventListener("DOMContentLoaded", function (_event) { const listingTargetEl = window.document.querySelector('#listing-posts_biotech .list'); if (!listingTargetEl) { @@ -332,7 +360,7 @@