Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JonGretar committed Oct 7, 2024
1 parent 90defa4 commit ab90489
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 105 deletions.

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.
4 changes: 2 additions & 2 deletions _site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ <h3 class="no-anchor listing-title">
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="1" data-categories="R,TidyTuesday,Forestry" data-listing-date-sort="1639951200000" data-listing-file-modified-sort="1696753209880" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="4" data-listing-word-count-sort="714">
<div class="quarto-post image-right" data-index="1" data-categories="R,TidyTuesday,Forestry" data-listing-date-sort="1639951200000" data-listing-file-modified-sort="1728323260818" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="4" data-listing-word-count-sort="698">
<div class="thumbnail">
<p><a href="./posts/2021-12-20-deforestation/index.html" class="no-external"></a></p><a href="./posts/2021-12-20-deforestation/index.html" class="no-external">
<p><img loading="lazy" src="./posts/2021-12-20-deforestation/index_files/figure-html/forest-area-1.png" class="thumbnail-image"></p>
Expand Down Expand Up @@ -288,7 +288,7 @@ <h3 class="no-anchor listing-title">
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="2" data-categories="R,Quarto" data-listing-date-sort="1619298000000" data-listing-file-modified-sort="1696753209879" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="3" data-listing-word-count-sort="467">
<div class="quarto-post image-right" data-index="2" data-categories="R,Quarto" data-listing-date-sort="1619298000000" data-listing-file-modified-sort="1728323207950" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="3" data-listing-word-count-sort="452">
<div class="thumbnail">
<p><a href="./posts/2021-04-25-welcome/index.html" class="no-external"></a></p><a href="./posts/2021-04-25-welcome/index.html" class="no-external">
<p><img loading="lazy" src="./posts/2021-04-25-welcome/index_files/figure-html/final-1.png" class="thumbnail-image"></p>
Expand Down
162 changes: 78 additions & 84 deletions _site/posts/2021-12-20-deforestation/index.html

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.
2 changes: 1 addition & 1 deletion _site/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"href": "posts/2021-12-20-deforestation/index.html",
"title": "Deforestation",
"section": "",
"text": "knitr::opts_chunk$set(\n warning=FALSE,\n code_folding=FALSE\n)\nI’ve been wanting to play around in the TidyTuesday scene for a while now. The deforestation dataset (Ritchie and Roser 2021) is obviously of specific interest to me as a forest science student so I chose that one to begin with.\nlibrary(tidyverse)\n\n── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──\n\n\n✔ ggplot2 3.3.5 ✔ purrr 0.3.4\n✔ tibble 3.1.6 ✔ dplyr 1.0.9\n✔ tidyr 1.1.4 ✔ stringr 1.4.0\n✔ readr 2.0.2 ✔ forcats 0.5.1\n\n\n── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──\n✖ dplyr::filter() masks stats::filter()\n✖ dplyr::lag() masks stats::lag()\n\nlibrary(rmarkdown)\nlibrary(hrbrthemes)\n\nNOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.\n\n\n Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and\n\n\n if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow\n\nlibrary(ggbump) # For the maps and rank graph\ntuesdata &lt;- readRDS(\"posts/2021-12-20-deforestation/deforestation.data\")"
"text": "knitr::opts_chunk$set(\n warning=FALSE,\n code_folding=FALSE\n)\nI’ve been wanting to play around in the TidyTuesday scene for a while now. The deforestation dataset (Ritchie and Roser 2021) is obviously of specific interest to me as a forest science student so I chose that one to begin with.\nlibrary(tidyverse)\n\n── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──\n✔ dplyr 1.1.3 ✔ readr 2.1.4\n✔ forcats 1.0.0 ✔ stringr 1.5.0\n✔ ggplot2 3.4.3 ✔ tibble 3.2.1\n✔ lubridate 1.9.3 ✔ tidyr 1.3.0\n✔ purrr 1.0.2 \n── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──\n✖ dplyr::filter() masks stats::filter()\n✖ dplyr::lag() masks stats::lag()\nℹ Use the conflicted package (&lt;http://conflicted.r-lib.org/&gt;) to force all conflicts to become errors\n\nlibrary(rmarkdown)\nlibrary(hrbrthemes)\n\nNOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.\n Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and\n if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow\n\nlibrary(ggbump) # For the maps and rank graph\ntuesdata &lt;- readRDS(\"posts/2021-12-20-deforestation/deforestation.data\")"
},
{
"objectID": "posts/2021-12-20-deforestation/index.html#rank-of-northern-countries",
Expand Down
36 changes: 29 additions & 7 deletions posts/2021-04-25-welcome/index.qmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
title: "First Quarto post"
description: |
This is just a demo post. The idea is to test the capabilities of Quarto as a blogging platform. In this post I am just trying out a few capabilities of Quarto and how well it is suited to the kinds of things I would like to write about. Amongst other things. However, time will tell on how well I can focus on writing articles here.
This is just a demo post. The idea is to test the capabilities of Quarto as a
blogging platform. In this post I am just trying out a few capabilities of
Quarto and how well it is suited to the kinds of things I would like to write
about. Amongst other things. However, time will tell on how well I can focus
on writing articles here.
date: 04-25-2021
image: index_files/figure-html/final-1.png
bibliography: library.bib
Expand Down Expand Up @@ -31,9 +35,16 @@ trees <- read_delim("posts/2021-04-25-welcome/plot2.csv", ";",

## Why Quarto?

There are a few reasons for why I would like to try [Quarto](https://quarto.org) [@quarto] as my blogging platform. As I want to write more things of scientific nature I would like to be able to easily cite articles. For example later in this example page I use volume functions from the article *Single-tree biomass and stem volume functions for eleven tree species used in Icelandic forestry* [@arnórsnorrason2006].
There are a few reasons for why I would like to try
[Quarto](https://quarto.org) [@quarto] as my blogging platform. As I want to
write more things of scientific nature I would like to be able to easily cite
articles. For example later in this example page I use volume functions from
the article *Single-tree biomass and stem volume functions for eleven tree
species used in Icelandic forestry* [@arnórsnorrason2006].

Other reasons are the capabilities of working with the data right in the blogging system and creating the charts and tables in the same area as I write the post.
Other reasons are the capabilities of working with the data right in the
blogging system and creating the charts and tables in the same area as I write
the post.

## Working with data

Expand All @@ -51,7 +62,10 @@ trees$dbh <- (trees$diam1 + trees$diam2) / 2
trees$ba <- (trees$dbh/200)^2 * pi
```

For the next trick we use linear regressions to calculate the expected height of the trees. We then use `coalesce()` to copy back the height we already knew. From there we can calculate the volume of each tree using the volume functions [@arnórsnorrason2006].
For the next trick we use linear regressions to calculate the expected height
of the trees. We then use `coalesce()` to copy back the height we already knew.
From there we can calculate the volume of each tree using the volume functions
[@arnórsnorrason2006].

```{r}
trees$height <- lm(height_measured ~ ba, data=trees) %>%
Expand Down Expand Up @@ -79,13 +93,21 @@ trees |> ggplot(aes(dbh, height_measured)) +

## Math with R

Using LaTeX math symbols we can communicate mathematical functions in a nice manner. For example we can talk about BAL as described by Arne Pommerening's excellent article [*Basal area in larger trees and the growth compensation point*](https://blogg.slu.se/forest-biometrics/2017/05/26/basal-area-in-larger-trees-and-the-growth-compensation-point/) where he explains BAL as such:
Using LaTeX math symbols we can communicate mathematical functions in a nice
manner. For example we can talk about BAL as described by Arne Pommerening's
excellent article [*Basal area in larger trees and the growth compensation
point*](https://blogg.slu.se/forest-biometrics/2017/05/26/basal-area-in-larger-trees-and-the-growth-compensation-point/)
where he explains BAL as such:

> *BAL* is related to available light, since with increasing basal area of larger trees there is less light available for smaller trees. In a sense *BAL* is a surrogate for light measurements with the benefit that stem diameters and basal area are easier to measure.
> *BAL* is related to available light, since with increasing basal area of
> larger trees there is less light available for smaller trees. In a sense
> *BAL* is a surrogate for light measurements with the benefit that stem
> diameters and basal area are easier to measure.
$$BAL_i(t) = G(t) \cdot (1 - p_i(t)) \text{ where } p_i(t) = \frac{1}{G(t)} \sum_{\leq g_i(t)} g_i(t)$$

He also give us an example function in R. Let us use it to calculate the BAL of individual trees in our example data.
He also give us an example function in R. Let us use it to calculate the BAL of
individual trees in our example data.

```{r}
bal <- function(ba, area) {
Expand Down
41 changes: 32 additions & 9 deletions posts/2021-12-20-deforestation/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ knitr::opts_chunk$set(
)
```

I've been wanting to play around in the [TidyTuesday](https://github.com/rfordatascience/tidytuesday) scene for a while now. The deforestation dataset [@deforestation2021] is obviously of specific interest to me as a forest science student so I chose that one to begin with.
I've been wanting to play around in the
[TidyTuesday](https://github.com/rfordatascience/tidytuesday) scene for a
while now. The deforestation dataset [@deforestation2021] is obviously of
specific interest to me as a forest science student so I chose that one to
begin with.

```{r}
library(tidyverse)
Expand All @@ -36,9 +40,14 @@ tuesdata <- readRDS("posts/2021-12-20-deforestation/deforestation.data")

## Rank of Northern Countries

I'm gonna start it simple and the generate a simple ranked bump chart of the net change of forestry of the northern European countries using ggbump[@ggbump].
I'm gonna start it simple and the generate a simple ranked bump chart of the
net change of forestry of the northern European countries using
ggbump[@ggbump].

First of it to filter in the northern countries that we wish to see. We also need to filter out the 2015 data as there seem to be gaps in them. For each year we proceed to use `rank()` to rank each country by the net change in forest area.
First of it to filter in the northern countries that we wish to see. We also
need to filter out the 2015 data as there seem to be gaps in them. For each
year we proceed to use `rank()` to rank each country by the net change in
forest area.

```{r}
countries <- c('Iceland', 'Finland', 'Sweden', 'Norway', 'Denmark')
Expand All @@ -54,7 +63,9 @@ ranked <- tuesdata$forest |>
ranked |> paged_table()
```

With this data it is pretty straight forward to use `geom_bump()` to generate a simple bump map. I'm gonna use hrbrthemes[@hrbrthemes] as a base theme for my graphs as it tends to be my default theme.
With this data it is pretty straight forward to use `geom_bump()` to generate a
simple bump map. I'm gonna use hrbrthemes[@hrbrthemes] as a base theme for my
graphs as it tends to be my default theme.

```{r}
#| label: ranked
Expand All @@ -80,11 +91,16 @@ ranked |>
theme(legend.position = "none")
```

It turns out that this was not a good way of viewing this data. But oh well. I will leave it here nevertheless.
It turns out that this was not a good way of viewing this data. But oh well. I
will leave it here nevertheless.

## Countries with the largest change of forest area.

Next to explore this same table I wish to generate a lollipop chart showing the countries of the world with the lagest positive and negative change in forest cover. To do this I take countries the top 20 *absolute* values of net forest conversion, I reorder those by real net_forest_conversion and then prepare a text for the coloring of negative or positive values.
Next to explore this same table I wish to generate a lollipop chart showing the
countries of the world with the lagest positive and negative change in forest
cover. To do this I take countries the top 20 *absolute* values of net forest
conversion, I reorder those by real net_forest_conversion and then prepare a
text for the coloring of negative or positive values.

```{r}
forest_countries <- tuesdata$forest |>
Expand All @@ -101,7 +117,9 @@ forest_countries <- tuesdata$forest |>
forest_countries |> paged_table()
```

From this we can generate a basic lollipop chart using `geom_segment()` and `geom_point()` as the base for the lollipops. I also flip the coordinates as it is better than rotating the country labels to a near vertical position.
From this we can generate a basic lollipop chart using `geom_segment()` and
`geom_point()` as the base for the lollipops. I also flip the coordinates as it
is better than rotating the country labels to a near vertical position.

```{r}
#| label: forest-area
Expand Down Expand Up @@ -134,6 +152,11 @@ forest_countries |>
)
```

I kind of like this one. The reason I chose to use the absolute values, instead of having the 0 in the middle, was to make it easier to compare the rate of change. It highlights the crazy deforestation going on in Brazil and the even crazier amount of forest being planted in China.
I kind of like this one. The reason I chose to use the absolute values, instead
of having the 0 in the middle, was to make it easier to compare the rate of
change. It highlights the crazy deforestation going on in Brazil and the even
crazier amount of forest being planted in China.

To see how I use this data for map making check out my [next
post](/posts/2022-01-10-forests-of-europe/)

To see how I use this data for map making check out my [next post](/posts/2022-01-10-forests-of-europe/)

0 comments on commit ab90489

Please sign in to comment.