Skip to content

Commit

Permalink
markdown source builds
Browse files Browse the repository at this point in the history
Auto-generated via `{sandpaper}`
Source  : b8fe41b
Branch  : main
Author  : Kaija Gahm <[email protected]>
Time    : 2024-12-31 22:16:12 +0000
Message : Merge pull request #99 from carpentries-incubator/peter_edits

episode 2 ready for website review
  • Loading branch information
actions-user committed Dec 31, 2024
1 parent 7dd2930 commit ff98c5e
Show file tree
Hide file tree
Showing 9 changed files with 1,774 additions and 4 deletions.
73 changes: 70 additions & 3 deletions 2-identify-the-problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,73 @@ Now, we do see that by subsetting to the "Rodent" taxa, we are losing about 357
rodents <- rodents %>% filter(taxa == "Rodent")
```



::::::: challenge

There are 3 lines of code below, and each attempts to create the same plot. Identify which produces a syntax error, which produces a semantic error, and which correctly creates the plot (hint: this may require you inferring what type of graph we're trying to create!)




A. `ggplot(rodents) + geom_bin_2d(aes(month, plot_type))`

B. `ggplot(rodents) + geom_tile(aes(month, plot_type), stat = "count")`

C. `ggplot(rodents) + geom_tile(aes(month, plot_type))`


::::: solution

In this case, A correctly creates the graph, plotting as colors in the tile the number of times an observation is seen. It essentially runs the following lines of code:


``` r
rodents_summary <- rodents %>% group_by(plot_type, month) %>% summarize(count=n())
```

``` output
`summarise()` has grouped output by 'plot_type'. You can override using the
`.groups` argument.
```

``` r
ggplot(rodents_summary) + geom_tile(aes(month, plot_type, fill=count))
```

<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-9-1.png" style="display: block; margin: auto;" />

B is a syntax error, and will produce the following error:


``` r
ggplot(rodents) + geom_tile(aes(month, plot_type), stat = "count")
```

``` error
Error in `geom_tile()`:
! Problem while computing stat.
ℹ Error occurred in the 1st layer.
Caused by error in `setup_params()`:
! `stat_count()` must only have an x or y aesthetic.
```

Finally, C is a semantic error. It produces a plot, which is rather meaningless:


``` r
ggplot(rodents) + geom_tile(aes(month, plot_type))
```

<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-11-1.png" style="display: block; margin: auto;" />

:::::


:::::::



## Summary

In general, when encountering a semantic error for which a remedy is not immediately apparent, some steps to take include:
Expand Down Expand Up @@ -287,7 +354,7 @@ facet_wrap(~species)
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
```

<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-12-1.png" style="display: block; margin: auto;" />
<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-15-1.png" style="display: block; margin: auto;" />

Our improved code here looks good. Checking the dimensions of our subsetted data frame using the dim() function confirms we now have all the *Dipodomys* observations, and our plot is looking better. In general, having a 'print' statement or some other output before plots or other major steps can be a good way to check your code is producing intermediate results consistent with your expectations.

Expand Down Expand Up @@ -321,7 +388,7 @@ ggplot(krats, aes(date, fill=plot_type)) +
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
```

<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-13-1.png" style="display: block; margin: auto;" />
<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-16-1.png" style="display: block; margin: auto;" />

This looks much better, and is easier to see the trends over time as well. Note our x axis still shows bins with year labelings, but the continuous spread of our data over these bins shows that dates are treated more continuously and fall more continuously within histogram bins.

Expand Down Expand Up @@ -386,6 +453,6 @@ krats %>%
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
```

<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-14-1.png" style="display: block; margin: auto;" />
<img src="fig/2-identify-the-problem-rendered-unnamed-chunk-17-1.png" style="display: block; margin: auto;" />

It looks like the study change helped to reduce *merriami* sightings in the Rodent and Short-term Krat exclosures.
81 changes: 81 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

#------------------------------------------------------------
# Values for this lesson.
#------------------------------------------------------------

# Which carpentry is this (swc, dc, lc, or cp)?
# swc: Software Carpentry
# dc: Data Carpentry
# lc: Library Carpentry
# cp: Carpentries (to use for instructor training for instance)
# incubator: The Carpentries Incubator
carpentry: 'incubator'

# Overall title for pages.
title: 'RRRRR, I’m stuck!'

# Date the lesson was created (YYYY-MM-DD, this is empty by default)
created: 2024-05-14

# Comma-separated list of keywords for the lesson
keywords: 'R, reprex, help, The Carpentries, error, debug, reproducible example'

# Life cycle stage of the lesson
# possible values: pre-alpha, alpha, beta, stable
life_cycle: 'pre-alpha'

# License of the lesson
license: 'CC-BY 4.0'

# Link to the source repository for this lesson
source: 'https://github.com/carpentries-incubator/R-help-reprexes'

# Default branch of your lesson
branch: 'main'

# Who to contact if there are any issues
contact: '[email protected]'

# Navigation ------------------------------------------------
#
# Use the following menu items to specify the order of
# individual pages in each dropdown section. Leave blank to
# include all pages in the folder.
#
# Example -------------
#
# episodes:
# - introduction.md
# - first-steps.md
#
# learners:
# - setup.md
#
# instructors:
# - instructor-notes.md
#
# profiles:
# - one-learner.md
# - another-learner.md

# Order of episodes in your lesson
episodes:
- 1-intro-reproducible-examples.md
- 2-identify-the-problem.Rmd
- 3-minimal-reproducible-data.Rmd
- 4-minimal-reproducible-code.Rmd
- 5-asking-your-question.md

# Information for Learners
learners:

# Information for Instructors
instructors:

# Learner Profiles
profiles:

# Customisation ---------------------------------------------
#
# This space below is where custom yaml items (e.g. pinning
# sandpaper and varnish versions) should live
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"index.md" "569a77710d887c7a9a3d1ff967914168" "site/built/index.md" "2024-12-31"
"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2024-12-31"
"episodes/1-intro-reproducible-examples.md" "b7c7f7f8b52273b2fa9135e453a84a81" "site/built/1-intro-reproducible-examples.md" "2024-12-31"
"episodes/2-identify-the-problem.Rmd" "3fe213a92a29b9c2ae5f7eaab51abf3e" "site/built/2-identify-the-problem.md" "2024-12-31"
"episodes/2-identify-the-problem.Rmd" "124f25f36c9c6b37b143046cac63cfdf" "site/built/2-identify-the-problem.md" "2024-12-31"
"episodes/3-minimal-reproducible-data.Rmd" "8075e333db75d0fb5997a4c03b451def" "site/built/3-minimal-reproducible-data.md" "2024-12-31"
"episodes/4-minimal-reproducible-code.Rmd" "24559880b473fa56084c693d06b7e6d8" "site/built/4-minimal-reproducible-code.md" "2024-12-31"
"episodes/5-asking-your-question.md" "2e4d11a3fcb71090806bb1f32b088d9a" "site/built/5-asking-your-question.md" "2024-12-31"
Expand Down
Loading

0 comments on commit ff98c5e

Please sign in to comment.