diff --git a/.gitignore b/.gitignore index 683a317..a7fd535 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ .Rhistory .RData *.html +Test.* +data/ diff --git a/ReadMe.md b/ReadMe.md index 8013e9d..39d51df 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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 diff --git a/prep/Instructor.Rmd b/prep/Instructor.Rmd index 69f6089..05b6c1d 100644 --- a/prep/Instructor.Rmd +++ b/prep/Instructor.Rmd @@ -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 diff --git a/prep/Preparation-RNotebook.ipynb b/prep/Preparation-RNotebook.ipynb new file mode 100644 index 0000000..46ab470 --- /dev/null +++ b/prep/Preparation-RNotebook.ipynb @@ -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 +} diff --git a/prep/Preparation-RStudio.Rmd b/prep/Preparation-RStudio.Rmd index 7801ee6..60b7465 100644 --- a/prep/Preparation-RStudio.Rmd +++ b/prep/Preparation-RStudio.Rmd @@ -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. @@ -17,7 +19,7 @@ library(lubridate) library(ratdat) ``` -## Lessons Snippits +## Plotting ```{r} #install.packages("ggplot2") @@ -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") +```