--- title: "Capstone project" author: "Karl Broman" date: "2017-01-11" output: html_document --- Capstone project for Data Carpentry course. ## 1: Load the data ```{r load_data, message=FALSE} library(dplyr) library(ggplot2) surveys <- read.csv("http://kbroman.org/datacarp/portal_data_joined.csv") ``` There are `r ncol(surveys)` columns and `r nrow(surveys)` rows. ## 2: Boxplots of weight by sex Boxplots of weight by sex, omitting individuals with missing sex. ```{r boxplots_weight} surveys %>% select(weight, sex) %>% filter(sex != "", !is.na(sex)) %>% ggplot() + geom_boxplot(aes(x=sex, y=weight)) ``` ## 3. Histogram of hindfoot lengths ```{r hist_hindfootlength} surveys %>% filter(!is.na(hindfoot_length)) %>% ggplot() + geom_histogram(aes(x=hindfoot_length), bins=150) ``` ## 4. scatterplots of hindfoot length vs weight for 3 species ```{r scatterplots} surveys %>% filter(species_id %in% c("DM", "DO", "DS")) %>% filter(!is.na(weight), !is.na(hindfoot_length)) %>% ggplot(aes(x=hindfoot_length, y=weight)) + geom_point(aes(color=species_id)) + facet_grid(species_id ~ .) ``` ## 5. Plot of counts of "DM" in "Rodent Exclosure" plots over time ```{r plot_counts_by_year} counts <- surveys %>% filter(species_id == "DM") %>% filter(plot_type=="Rodent Exclosure") %>% group_by(year) %>% tally() counts %>% ggplot(aes(x=year, y=n)) + geom_line() ``` ## 6. Table with counts of "DM" by plot_type in 1977 ```{r table_plot_type} counts1977 <- surveys %>% filter(species_id == "DM", year==1977) %>% group_by(plot_type) %>% tally() %>% select(plot_type, n) knitr::kable(counts1977) ```