Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit

Permalink
Prep completed for ecology lessons
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiddelkoop committed May 22, 2024
1 parent dc7accc commit e4da6bb
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.Rhistory
.RData
*.html
Test.*
data/
9 changes: 9 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
## Lessons

Lessons (Day 1):

* https://datacarpentry.org/R-ecology-lesson-alternative/index.html
* https://datacarpentry.org/R-ecology-lesson-alternative/introduction-r-rstudio.html
* https://datacarpentry.org/R-ecology-lesson-alternative/visualizing-ggplot.html
* https://datacarpentry.org/R-ecology-lesson-alternative/how-r-thinks-about-data.html

Lessons (Day 2):

* https://datacarpentry.org/R-ecology-lesson-alternative/working-with-data.html
* https://datacarpentry.org/R-ecology-lesson/05-r-and-databases.html


## Hints

RStudio keyboard:

* cmd-r/ctrl-r - Run a line and move to the next
* option-r/alt-r - Run a single line and stay on that line
1 change: 1 addition & 0 deletions prep/Instructor.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ git config push.default simple
* R Notebooks seem fragile and Caching output seems dangerous. Use "Chunk Output Inline" for a more Notebook experence or use Juypter!
* R Markdown is a bit different (lists for example) than other markdown.
* With Rmd files I am a fan of using the console (chunk output in console) and use cmd-enter to run each line (opt-enter for not advancing cursor) for development.
* You can auto-install packages in a Rmd file. Need to figure out proper pedegody for this.

# Test

Expand Down
117 changes: 117 additions & 0 deletions prep/Preparation-RNotebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "9dd1774e-6446-4f7f-b3ee-3ac0dcd5a027",
"metadata": {},
"source": [
"# R Notebook Prep\n",
"\n",
"This produces a large graphics. Clear all outputs before saving."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "03dca8c7-f3a4-48c4-8a9e-17b6701ce59b",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"## Setup system - run only once\n",
"\n",
"# Configure mirror\n",
"options(repos = list(CRAN=\"http://cran.rstudio.com/\"))\n",
"\n",
"# Install basic packages\n",
"install.packages(c(\"tidyverse\", \"lubridate\", \"ratdat\"))\n",
"\n",
"# Install plotting packages\n",
"install.packages(\"ggplot2\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "942ae10c-eec7-4ca0-be76-c268872c150f",
"metadata": {},
"outputs": [],
"source": [
"library(tidyverse)\n",
"library(lubridate)\n",
"library(ratdat)\n",
"library(ggplot2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ade46ad-0ce2-4106-b0cd-5377e84d51b4",
"metadata": {},
"outputs": [],
"source": [
"ggplot(data = complete_old, mapping = aes(x = weight, y = hindfoot_length)) +\n",
" geom_point()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6605dcea-b970-4591-82eb-7928512fcc4f",
"metadata": {},
"outputs": [],
"source": [
"myplot <- ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length)) +\n",
" geom_jitter(aes(color = plot_type), alpha = 0.2) +\n",
" geom_boxplot(outlier.shape = NA, fill = NA)\n",
"\n",
"myplot\n",
"\n",
"myplot +\n",
" theme_bw() +\n",
" theme(axis.title = element_text(size = 14), \n",
" legend.position = \"none\", \n",
" panel.grid.major.x = element_blank()) +\n",
" labs(title = \"Rodent size by plot type\",\n",
" x = \"Plot type\",\n",
" y = \"Hindfoot length (mm)\",\n",
" color = \"Plot type\") +\n",
" facet_wrap(vars(sex), ncol = 1)"
]
},
{
"cell_type": "markdown",
"id": "b65f2312-4e9e-4e36-895e-e591f7c9db9b",
"metadata": {},
"source": [
"This produces a large graphics. Clear all outputs before saving."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c26e0424-4115-48b2-a0d9-97dabee03875",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "4.3.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
33 changes: 32 additions & 1 deletion prep/Preparation-RStudio.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ editor_options:
---
# R Ecology

Test the technology prep (not show notes)

## Install Packages

Run the (Setup.Rmd)[Setup.Rmd] RStudio notebook once.
Expand All @@ -17,7 +19,7 @@ library(lubridate)
library(ratdat)
```

## Lessons Snippits
## Plotting

```{r}
#install.packages("ggplot2")
Expand Down Expand Up @@ -71,3 +73,32 @@ myplot +
```

## Understanding Data

```{r}
class(complete_old)
head(complete_old)
# provide a summary
summary(complete_old)
```

## Working with Data

Download Data (once)
```{r}
dir.create('data/cleaned', recursive = TRUE)
download.file('https://www.michaelc-m.com/Rewrite-R-ecology-lesson/data/cleaned/surveys_complete_77_89.csv', 'data/cleaned/surveys_complete_77_89.csv')
```

Load data
```{r}
surveys <- read_csv("data/cleaned/surveys_complete_77_89.csv")
class(surveys)
select(surveys, plot_id, species_id, hindfoot_length)
```

Write Data
```{r}
write_csv(surveys, "data/cleaned/test.csv")
```

0 comments on commit e4da6bb

Please sign in to comment.