homework/
folderfull_name_hw##.R
justin_pomeranz_hw01.R
Source with echo
volume
is on the last line of the example
below# 2.1 example
w = 2
h = 3
l = 1.5
w
h
l
#2.2 example
volume = w * h * l
volume
Make sure that tidyverse
is downloaded on the
machine you’re using
You can check this by clicking on the Packages
tab
in the Files, Plots, Packages… panel and scrolling
down
If you need to download the package, copy the following code into your Console panel and run it **Do not put it in your homework script*
install.packages("ggplot2")
Copy the following code into the beginning of your homework
script to load the ggplot2
package:
# load libraries
library(tidyverse)
Download the galapagos-finches.csv
data from D2L and put
it in your data/
folder in your Class R project.
Read the data file into R using the following command:
# read in full data set
finch <- read.csv("data/galapago-finches.csv")
dplyr
and ggplot2
0.1 Use head()
to print out the first few rows of the
finch
data.
0.2 Print out the last few rows of the finch
data.
0.3 Print out the names of the columns in the finch
data.
0.4 Use select()
to print out only the
species
column.
0.5 Use select()
to print out the year
,
species
and blength
columns, in that
order.
0.6 Use arrange()
to print out the finch
data in order based on the blength
column.
0.7 Use arrange()
to print out the finch
data in order based on the species
, year
, and
bdepth
columns, in that order.
0.8 Use mutate()
to add a new column called
beak_area
, and have its value equal to
blength * bdepth
.
0.9 Use summarize
to calculate the average
blength
across the whole finch
data set.
0.10 Use group_by()
and summarize
to
calculate the average blength
for each species
in finch
data set.
1.1 Make a histogram of the blength
column.
1.2 Make a histogram of the blength
column and give it a
descriptive title (5-7 words) and change the the x-axis label to be more
easily read and include the units (mm).
1.3 Make a histogram of the blength
column with 100
bins.
1.4 Make a histogram of the blength
column where the
binwidth is 1.
1.5 Make a boxplot of the blength
.
1.6 Make a boxplot of the blength
but change the fill
color to one of your choice. (See a list of color
names available in ggplot)
2.1 Make a boxplot of the blength
, but have the fill
color vary based on the species.
2.2 Make a boxplot of the blength
, but have the fill
color vary based on the year collected. (Careful of continuous
vs. categorical variables. )
2.3 Make a boxplot of the blength
, but have the fill
color vary based on the year, and have species mapped to the y-axis.
3.1 Use geom_point()
to make a scatter plot with
blength
on the x-axis, and bdepth
on the
y-axis.
3.2 Use geom_point()
to make a scatter plot with
blength
on the x-axis, and bdepth
on the
y-axis. Also include a linear regression on the plot for the whole data
set (there should be one line on your graph).
3.3 Use geom_point()
to make a scatter plot with
blength
on the x-axis, and bdepth
on the
y-axis. Also have the color of the points relate to the species, and
include a linear regression on the plot for each species separately
(there should be 2 lines on your graph).
3.4 Repeat the graph you made in 3.3 above but include a separate facet for each year of data.
4.1 Use mutate()
to create a new variable in the
finch
data set. This new variable should be equal to beak
length \(\times\) beak depth. Make a
plain histogram showing the distribution of your new variable.
4.2 Do the same thing as in 4.1, but this time, only plot the data from 1975, and map the fill color to the species variable.
4.3 Do the same thing as in 4.2, but add a descriptive title and x-axis label.
4.4 Do the same thing as in 4.1, but this time have the fill color mapped to species, and have a facet for each year.