diff --git a/.github/workflows/pr-close-signal.yaml b/.github/workflows/pr-close-signal.yaml index 9b129d5..b1303c2 100644 --- a/.github/workflows/pr-close-signal.yaml +++ b/.github/workflows/pr-close-signal.yaml @@ -8,7 +8,7 @@ on: jobs: send-close-signal: name: "Send closing signal" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: ${{ github.event.action == 'closed' }} steps: - name: "Create PRtifact" @@ -16,8 +16,7 @@ jobs: mkdir -p ./pr printf ${{ github.event.number }} > ./pr/NUM - name: Upload Diff - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: pr path: ./pr - diff --git a/.github/workflows/pr-comment.yaml b/.github/workflows/pr-comment.yaml index bb2eb03..f80d9d0 100644 --- a/.github/workflows/pr-comment.yaml +++ b/.github/workflows/pr-comment.yaml @@ -20,7 +20,7 @@ jobs: # - no .github files were committed test-pr: name: "Test if pull request is valid" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: > github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' @@ -74,7 +74,7 @@ jobs: create-branch: name: "Create Git Branch" needs: test-pr - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: ${{ needs.test-pr.outputs.is_valid == 'true' }} env: NR: ${{ needs.test-pr.outputs.number }} @@ -82,7 +82,7 @@ jobs: contents: write steps: - name: 'Checkout md outputs' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: md-outputs path: built @@ -120,7 +120,7 @@ jobs: comment-pr: name: "Comment on Pull Request" needs: [test-pr, create-branch] - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: ${{ needs.test-pr.outputs.is_valid == 'true' }} env: NR: ${{ needs.test-pr.outputs.number }} @@ -150,7 +150,7 @@ jobs: comment-changed-workflow: name: "Comment if workflow files have changed" needs: test-pr - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: ${{ always() && needs.test-pr.outputs.is_valid == 'false' }} env: NR: ${{ github.event.workflow_run.pull_requests[0].number }} @@ -182,4 +182,3 @@ jobs: with: pr: ${{ env.NR }} body: ${{ env.body }} - diff --git a/.github/workflows/pr-post-remove-branch.yaml b/.github/workflows/pr-post-remove-branch.yaml index 62c2e98..9419e2b 100644 --- a/.github/workflows/pr-post-remove-branch.yaml +++ b/.github/workflows/pr-post-remove-branch.yaml @@ -9,7 +9,7 @@ on: jobs: delete: name: "Delete branch from Pull Request" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: > github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' diff --git a/.github/workflows/pr-preflight.yaml b/.github/workflows/pr-preflight.yaml index d0d7420..34ad7ae 100644 --- a/.github/workflows/pr-preflight.yaml +++ b/.github/workflows/pr-preflight.yaml @@ -11,7 +11,7 @@ jobs: test-pr: name: "Test if pull request is valid" if: ${{ github.event.action != 'closed' }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: is_valid: ${{ steps.check-pr.outputs.VALID }} permissions: diff --git a/.github/workflows/pr-receive.yaml b/.github/workflows/pr-receive.yaml index 371ef54..7fbff6c 100644 --- a/.github/workflows/pr-receive.yaml +++ b/.github/workflows/pr-receive.yaml @@ -13,7 +13,7 @@ jobs: test-pr: name: "Record PR number" if: ${{ github.event.action != 'closed' }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: is_valid: ${{ steps.check-pr.outputs.VALID }} steps: @@ -25,7 +25,7 @@ jobs: - name: "Upload PR number" id: upload if: ${{ always() }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: pr path: ${{ github.workspace }}/NR @@ -48,7 +48,7 @@ jobs: build-md-source: name: "Build markdown source files if valid" needs: test-pr - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: ${{ needs.test-pr.outputs.is_valid == 'true' }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} @@ -58,10 +58,10 @@ jobs: MD: ${{ github.workspace }}/site/built steps: - name: "Check Out Main Branch" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: "Check Out Staging Branch" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: md-outputs path: ${{ env.MD }} @@ -107,20 +107,21 @@ jobs: shell: Rscript {0} - name: "Upload PR" - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: pr path: ${{ env.PR }} + overwrite: true - name: "Upload Diff" - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: diff path: ${{ env.CHIVE }} retention-days: 1 - name: "Upload Build" - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: built path: ${{ env.MD }} diff --git a/.github/workflows/sandpaper-main.yaml b/.github/workflows/sandpaper-main.yaml index e17707a..b3d1de8 100644 --- a/.github/workflows/sandpaper-main.yaml +++ b/.github/workflows/sandpaper-main.yaml @@ -21,7 +21,10 @@ on: jobs: full-build: name: "Build Full Site" - runs-on: ubuntu-latest + + # 2024-10-01: ubuntu-latest is now 24.04 and R is not installed by default in the runner image + # pin to 22.04 for now + runs-on: ubuntu-22.04 permissions: checks: write contents: write @@ -32,7 +35,7 @@ jobs: steps: - name: "Checkout Lesson" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: "Set up R" uses: r-lib/actions/setup-r@v2 diff --git a/.github/workflows/sandpaper-version.txt b/.github/workflows/sandpaper-version.txt index 1927038..084c7bd 100644 --- a/.github/workflows/sandpaper-version.txt +++ b/.github/workflows/sandpaper-version.txt @@ -1 +1 @@ -0.16.5 +0.16.10 diff --git a/.github/workflows/secondary_flow.yaml b/.github/workflows/secondary_flow.yaml new file mode 100644 index 0000000..542e34d --- /dev/null +++ b/.github/workflows/secondary_flow.yaml @@ -0,0 +1,31 @@ +name: Kopier fil til gh-pages + +on: + workflow_run: + workflows: ["01 Build and Deploy Site"] + types: + - completed + +jobs: + kopier-fil: + runs-on: ubuntu-latest + + steps: + - name: Checkout gh-pages branch + uses: actions/checkout@v3 + with: + ref: gh-pages + + - name: Download fil fra internettet + run: curl -o logotest.svg https://kubdatalab.github.io/R-intro/fig/logotest.svg + + - name: Kopier fil til det bestemte sted + run: mv logotest.svg assets/images/library-logo.svg + + - name: Commit og push ændringer + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git add . + git commit -m "Opdateret fil på gh-pages" + git push diff --git a/.github/workflows/update-cache.yaml b/.github/workflows/update-cache.yaml index 676d742..a011c0c 100644 --- a/.github/workflows/update-cache.yaml +++ b/.github/workflows/update-cache.yaml @@ -14,7 +14,7 @@ on: jobs: preflight: name: "Preflight Check" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: ok: ${{ steps.check.outputs.ok }} steps: @@ -36,14 +36,14 @@ jobs: check_renv: name: "Check if We Need {renv}" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: preflight if: ${{ needs.preflight.outputs.ok == 'true'}} outputs: needed: ${{ steps.renv.outputs.exists }} steps: - name: "Checkout Lesson" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - id: renv run: | if [[ -d renv ]]; then @@ -52,7 +52,7 @@ jobs: check_token: name: "Check SANDPAPER_WORKFLOW token" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: check_renv if: ${{ needs.check_renv.outputs.needed == 'true' }} outputs: @@ -69,14 +69,14 @@ jobs: name: "Update Package Cache" needs: check_token if: ${{ needs.check_token.outputs.repo== 'true' }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} RENV_PATHS_ROOT: ~/.local/share/renv/ steps: - name: "Checkout Lesson" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: "Set up R" uses: r-lib/actions/setup-r@v2 diff --git a/.github/workflows/update-workflows.yaml b/.github/workflows/update-workflows.yaml index 288bcd1..6414cf2 100644 --- a/.github/workflows/update-workflows.yaml +++ b/.github/workflows/update-workflows.yaml @@ -18,7 +18,7 @@ on: jobs: check_token: name: "Check SANDPAPER_WORKFLOW token" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: workflow: ${{ steps.validate.outputs.wf }} repo: ${{ steps.validate.outputs.repo }} @@ -31,12 +31,12 @@ jobs: update_workflow: name: "Update Workflow" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: check_token if: ${{ needs.check_token.outputs.workflow == 'true' }} steps: - name: "Checkout Repository" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Update Workflows id: update diff --git a/config.yaml b/config.yaml index d5d06aa..7993950 100644 --- a/config.yaml +++ b/config.yaml @@ -63,6 +63,7 @@ episodes: - getting_started.Rmd - further_mapping.Rmd - different_plots.Rmd +- facets.Rmd # Information for Learners learners: diff --git a/episodes/04-facets.Rmd b/episodes/facets.Rmd similarity index 71% rename from episodes/04-facets.Rmd rename to episodes/facets.Rmd index c82438d..4ff5680 100644 --- a/episodes/04-facets.Rmd +++ b/episodes/facets.Rmd @@ -2,28 +2,26 @@ title: "Facetting" teaching: 10 exercises: 5 -questions: +--- + +:::: questions - "What is facetting?" -objectives: +:::: + +:::: objectives - "Learn to use small multiples in your plots" -keypoints: -- "Facetting can make busy plots more understandable" -- "Grid facetting in two dimensions allows us to plot even more variables" -source: Rmd ---- +:::: + + -```{r options, include = FALSE} -source("../bin/chunk-options.R") -knitr_fig_path("04-") -``` ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(tidyverse) ``` -### Small multiples +## Small multiples If we only make one plot we quickly runs into the problem of trying to plot too much information in the plot. Here we plot the price against carat, @@ -36,7 +34,7 @@ ggplot(data = diamonds, mapping = aes(x = carat, y = price, color = color, shape ``` This is probably not the best way to discover patterns in the data. It is -actually so bad that ggplot warns us that we are using too many different shapes. +actually so bad that ggplot warns us that we are using too many different shapes! One way of handling that, is to plot "small multiples" of the data. @@ -52,17 +50,18 @@ ggplot(data = diamonds, mapping = aes(x = carat, y = price, color = color)) + Here we can see that the price rises more rapidly with size, for the better clarities, something that would have been impossible to see in the previous plot. -> ## Hidden connections -> -> facet_wrap is specified using the `~clarity` notation. -> -> This is similar to the way R specifies formulas: -> -> y ~ x would in eg. regressions in R specify that y is a function of x. -> -> Here we can think of it as "making plots that are a function of clarity" -> -{: .callout} +:::: callout +## Hidden connections + +facet_wrap is specified using the `~clarity` notation. + +This is similar to the way R specifies formulas: + +y ~ x would in eg. regressions in R specify that y is a function of x. + +Here we can think of it as "making plots that are a function of clarity" + +:::: The fundamental idea behind faceting, is the concept "small multiples", popularised by Edward Tufte. He describes it as (resembling) "the frames of a movie: a series @@ -73,27 +72,30 @@ much information, making it possible for the reader of the charts to walk through them one category at a time, and make comparisons. +:::: challenge +## Exercise -> ## exercise -> -> Plot price as a function of depth (price on the y-axis, depth on the x-axis), -> and facet by cut. If you want a colorful plot, color the points -> by color. -> -> > ## Solution -> > -> > ggplot(data = diamonds, mapping = aes(x = depth, y = price, color = color)) + -> > -> > geom_point() + -> > -> > facet_wrap(~cut) -> > -> > Note that for the better cuts, diamonds are cut to pretty -> > specific proportions. Worse (Fair) diamonds have more -> > varied proportions. -> > -> {: .solution} -{: .challenge} +Plot price as a function of depth (price on the y-axis, depth on the x-axis), +and facet by cut. If you want a colorful plot, color the points +by color. + +:::: solution +## Solution + +```{r solution, eval = FALSE} +ggplot(data = diamonds, mapping = aes(x = depth, y = price, color = color)) + + geom_point() + + facet_wrap(~cut) + +``` + + +Note that for the better cuts, diamonds are cut to pretty +specific proportions. Worse (Fair) diamonds have more +varied proportions. + +:::: +:::: ## More than one multiple @@ -113,3 +115,9 @@ diamonds %>% Be careful using facets, especially *facet_grid* when you work with small datasets. You might end up with too little data in each facet. + + +:::: keypoints +- "Facetting can make busy plots more understandable" +- "Grid facetting in two dimensions allows us to plot even more variables" +::::