This is a document that any and all of us can use to take notes and share difficult to type information (e.g. links). To start editing, click on the icons above that look either like a pencil (editing only) or a book (both editing and viewing). You can just start typing anywhere in the dark panel.
Apologies for the issue with sign-ins! The permissions have been reset so that you can edit without signing in.
To learn more about tidy data, check out this great paper.
OpenRefine is an open source tool for data cleaning. It can be very useful for dealing with typos, whitespace, and other common issues with data cleaning. Even better: it does all of its work without modifying the original data file, which is ideal for data management. Here is the lesson and here are setup instructions.
Exercise 1
Using faceting, find out how many years are represented in the census.
Is the column formatted as Number, Date, or Text? How does changing the format change the faceting display
Which years have the most and least observations?
Exercise 2
Rename the species column. Did any issues arise?
Exercise 3
- You might like to look for trends in your data by month of collection across years.
- How do you sort your data by month?
- How would you do this differently if you were instead trying to see all of your entries in chronological order?
Here is the lesson and here are setup instructions.
An example of how to embed code:
foo <- c(1,3)
What will happen in each of these examples? (hint: use class() to check the data type of your objects):
num_char <- c(1, 2, 3, "a")
num_logical <- c(1, 2, 3, TRUE)
char_logical <- c("a", "b", "c", TRUE)
tricky <- c(1, 2, 3, "4")
What happens when you combine numbers and characters?
character wins
What happens when you combine numbers and logical values?
numbers win
What happens when you combine characters and logical values?
character wins
Why do you think it happens?
download.file("https://ndownloader.figshare.com/files/2292169", "data/portal_data_joined.csv")
dplyr
Here is a dplyr
cheatsheet.
Here is a tidyr
cheatsheet.
Pipe exercise
Using pipes, subset the surveys data to include animals collected before 1995 and retain only the columns year, sex, and weight.
Mutation exercise
Create a new data frame from the surveys data that meets the following criteria: contains only the species_id column and a new column called hindfoot_half containing values that are half the hindfoot_length values. In this hindfoot_half column, there are no NAs and all values are less than 30.
Hint: think about how the commands should be ordered to produce this data frame
split-apply-combine exercises
- How many animals were caught in each plot_type surveyed?
- Use group_by() and summarize() to find the mean, min, and max hindfoot length for each species (using species_id). Also add the number of observations (hint: see ?n).
- What was the heaviest animal measured in each year? Return the columns year, genus, species_id, and weight.
tidyverse
and markdown
and test load using library()
Menu: https://www.jimmyjohns.com/downloadable-files/jj_menu_no_prices.pdf
Please type your name, the sandwich you would like to order, and any notes for your order
Name | Sandwich | Notes on order |
---|---|---|
Gerardo | Tukey breast, Provolone, Avo | 8" French Bread |
Jennifer | Tukey, Ham, Provolone | 8",tomato,mayomayomayomayo |
Bryan | Original roast beef | Order #377897850 |
Dan | Club Lulu #16 | 8" French bread, No tomato, Add Provolone cheese |
Greg | Tuna salad | 8" French bread |
Lindsey | Tuna salad | unwich lettuce wrap with sprouts and provolone cheese |
Kerrie | original size big italian (#9) | no mayo |
Steve | #8 | 9-grain wheat bread |
Stephen | #5 | 8" french bread |
Kevin | #5 | 8" french bread |
Jane | #4 | 8" french bread (plus sprouts) |
Tobin | #5 Italian | unwich (gluten free) |
Earl | #9 | original all the way |
Steve W | #14 | load it up |
Bruce | 8" JJBLT |
1335 W Elizabeth St
Fort Collins, CO 80521
ggplot2
Here is the base R cheatsheet. Here is an RStudio IDE cheatsheet that includes many keyboard shortcuts.
Here is the ggplot2 cheatsheet. Here is the ggplot2 website.
Here is where we made the subset data file for plotting: https://datacarpentry.org/R-ecology-lesson/03-dplyr.html#exporting_data
Plot Exercise
Use what you just learned to create a scatter (point) plot of weight over species_id with plot_type showing in different colors. Is this a good way to show this type of data?
Plot Exercise 2
- Boxplots are useful summaries, but hide the shape of the distribution. For example, if the distribution is bimodal, we would not see it in a boxplot. An alternative to the boxplot is the violin plot, where the shape (of the density of points) is drawn.
Replace the box plot with a violin plot; seegeom_violin()
.- In many types of data, it is important to consider the scale of the observations. For example, it may be worth changing the scale of the axis to better distribute the observations in the space of the plot. Changing the scale of the axes is done similarly to adding/modifying other components (i.e., by incrementally adding commands). Try representing weight on the log10 scale; see
scale_y_log10()
.- So far, we’ve looked at the distribution of weight within species. Try making a new plot to explore the distribution of another variable within each species.
- Create a boxplot for hindfoot_length. Overlay the boxplot layer on a jitter layer to show actual measurements.
- Add color to the data points on your boxplot according to the plot from which the sample was taken (plot_id).
Hint: Check the class for plot_id. Consider changing the class of plot_id from integer to factor. Why does this change how R makes the graph?
One great resource for colors: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
Here are two more:
http://colorbrewer2.org/
https://coolors.co/
We're going to be building a document that looks like this:
https://github.com/maglet/rmacc-rmarkdown/blob/master/Markdown_Demo.pdf
The script files I worked with are in this git repository:
https://github.com/maglet/rmacc-rmarkdown
But if you want, you can take another graph you made during the ggplot session and document it.
Here is the RStudio rmarkdown cheatsheet.
Slides for the git lesson are here. Here is the Happy Git and GitHub tutorial.
git config --global user.name "Vlad Dracula"
git config --global user.email "vlad@tran.sylvan.ia"