Learning Objectives

Following this assignment students should be able to:

  • understand the basic plot function of ggplot2
  • import ‘messy’ data with missing values and extra lines
  • execute and visualize a regression analysis

Reading

Lecture Notes

  1. Paths
  2. Basic Reproducibility

Exercises

  1. Bird Banding Multiple Vectors (optional)

    El número de aves anilladas en unos sitios de muestreo ha sido contado por su equipo de campo e ingresado en el siguiente vector. Los conteos se ingresan en el orden pertinente al sitio de muestreo, es decir, la posición 1 del vector corresponde a los pájaros contados en el sitio de conteo 1. Un segundo vector contiene información sobre la cantidad de árboles en cada sitio de muestreo. Corte y pegue el vector en su tarea y responda las siguientes preguntas usando funciones predeterminadas. Imprima el resultado a la pantalla.

    number_of_birds <- c(28, 32, 1, 0, 10, 22, 30, NA, 145, 27, 
    36, 25, 9, 38, 21, 12, 122, 87, 36, 3, 0, 5, 55, 62, 98, 32, 
    900, 33, 14, 39, 56, 81, 29, 38, 1, 0, 143, 37, 98, 77, 92, 
    83, 34, 98, 40, 45, 51, 17, 22, 37, 48, NA, 91, 73, 54, 46,
    102, 273, 600, 10, 11)
    number_of_trees <- c(10, 12, 2, 3, 10, 8, 19, 19, 14, 3, 
    4, 5, 8, 4, 8, 1, 12, 10, 3, 1, 2, 3, 5, 6, 8, 2, 
    90, 3, 4, 3, 6, 8, NA, 4, 0, 1, 14, 3, 10, NA, 9, 
    8, 4, 8, 4, 4, 5, 1, 2, 3, 5, 4, 10, 7, 5, 8,
    10, 30, 26, 1, 6)
    
    1. ¿Cuántos sitios de muestreo hay?
    2. ¿Cuántas aves se contaron en el sitio de muestreo 26?
    3. ¿Cuál es el mayor número de aves contadas?
    4. ¿Cuál es el número promedio de aves contadas?
    5. ¿Cuál es el número total de árboles contados en todos los sitios de muestreo?
    6. ¿Cuál es el menor número de árboles contados?
    7. Produzca un vector que contenga los conteos de aves en sitios de muestreo con al menos 10 árboles.
    8. Produzca un vector que contenga el número de árboles contados en sitios de muestreo con al menos 10 árboles.
    9. Combine los vectores number_of_birds y number_of_trees en un dataframe (marco de datos) como columnas. Incluya una tercera columna de año, llamada year, con el año 2012 en cada fila, finalmente incluya una cuarta columna de sitio de conteo, llamada site, que contenga los números del 1 al 61.
    Expected outputs for Bird Banding Multiple Vectors:
  2. Bird Banding Multiple Vectors (optional)

    The number of birds banded at a series of sampling sites has been counted by your field crew and entered into the following vector. Counts are entered in order and sites are numbered starting at one. There is also information on the number of trees at each site. Cut and paste the vector into your assignment and then answer the following questions by using code and printing the result to the screen.

    number_of_birds <- c(28, 32, 1, 0, 10, 22, 30, NA, 145, 27, 
    36, 25, 9, 38, 21, 12, 122, 87, 36, 3, 0, 5, 55, 62, 98, 32, 
    900, 33, 14, 39, 56, 81, 29, 38, 1, 0, 143, 37, 98, 77, 92, 
    83, 34, 98, 40, 45, 51, 17, 22, 37, 48, NA, 91, 73, 54, 46,
    102, 273, 600, 10, 11)
    number_of_trees <- c(10, 12, 2, 3, 10, 8, 19, 19, 14, 3, 
    4, 5, 8, 4, 8, 1, 12, 10, 3, 1, 2, 3, 5, 6, 8, 2, 
    90, 3, 4, 3, 6, 8, NA, 4, 0, 1, 14, 3, 10, NA, 9, 
    8, 4, 8, 4, 4, 5, 1, 2, 3, 5, 4, 10, 7, 5, 8,
    10, 30, 26, 1, 6)
    
    1. How many sites are there?
    2. How many birds were counted at the 26th site?
    3. What is the largest number of birds counted?
    4. What is the average number of birds seen at a site?
    5. What is the total number of trees counted across all of the sites?
    6. What is the smallest number of trees counted?
    7. Produce a vector with the number of birds counted on sites with at least 10 trees.
    8. Produce a vector with the number of trees counted on sites with at least 10 trees.
    9. Combine the number_of_birds and number_of_trees vectors into a dataframe that also includes a year column with the year 2012 in every row and site column containing the numbers 1 through 61.
    Expected outputs for Bird Banding Multiple Vectors: 1
  3. Portal Data Review (optional)

    If surveys.csv, species.csv, and plots.csv are not available in your workspace download them:

    Load them into R using read.csv().

    1. Create a data frame with only data for the species_id DO, with the columns year, month, day, species_id, and weight.
    2. Create a data frame with only data for species IDs PP and PB and for years starting in 1995, with the columns year, species_id, and hindfoot_length, with no null values for hindfoot_length.
    3. Create a data frame with the average hindfoot_length for each species_id in each year with no null values.
    4. Create a data frame with the year, genus, species, weight and plot_type for all cases where the genus is "Dipodomys".
    5. Make a scatter plot with weight on the x-axis and hindfoot_length on the y-axis. Use a log10 scale on the x-axis. Color the points by species_id. Include good axis labels.
    6. Make a histogram of weights with a separate subplot for each species_id. Do not include species with no weights. Set the scales argument to "free_y" so that the y-axes can vary. Include good axis labels.
    7. (Challenge) Make a plot with histograms of the weights of three species, PP, PB, and DM, colored by species_id, with a different facet (i.e., subplot) for each of three plot_type’s Control, Long-term Krat Exclosure, and Short-term Krat Exclosure. Include good axis labels and a title for the plot. Export the plot to a png file.
    Expected outputs for Portal Data Review: 1 2 3 4

Assignment submission & checklist