Intro to Quantitative Ecology
hist()
boxplot()
plot()
barplot()
png()
These questions cover materials in:
Gardener chapter 6.
Read sections 6.1 to 6.5.
Remember you can skip the Excel sections.
Read 6.1 in detail.
Sections 6.2 - 6.4 are reference guides for plotting techniques in R.
You should focus on tables 6.1, 6.2, 6.4 - 6.6
You’ll need to download the file butterfly_table.csv
from the course GitHub page.
NOTES
butterfly table.csv
,
with a space between butterfly
and table
.read.csv()
to read the
data.We’ll be using a dataset consisting of various measurements of three species of penguins.
To use the dataset, you’ll need to use
install.packages()
to install the
palmerpenguins package:
install.packages("palmerpenguins")
After you’ve installed it, you can load it using either
library()
or require()
.
Once you’ve successfully installed/loaded the penguins data, you should be able to run the following code on your machine to produce a summary of the first 4 columns of the dataset:
summary(penguins[, 1:4])
## species island bill_length_mm bill_depth_mm
## Adelie :152 Biscoe :168 Min. :32.10 Min. :13.10
## Chinstrap: 68 Dream :124 1st Qu.:39.23 1st Qu.:15.60
## Gentoo :124 Torgersen: 52 Median :44.45 Median :17.30
## Mean :43.92 Mean :17.15
## 3rd Qu.:48.50 3rd Qu.:18.70
## Max. :59.60 Max. :21.50
## NA's :2 NA's :2
Review the of
hist()
in R to produce histograms.
palmerpenguins
dataset.You must create a histogram of flipper length.
To get started, you can use my template code for a histogram of body mass:
hist(penguins$body_mass_g)
Notice the ugly title and x-axis label. Your histogram must have a better title and x-axis label than mine!
Review the section on boxplots (6.3.2) in Gardener.
palmerpenguins
dataset.You’ll need to create boxplot of flipper length grouped by sex.
I created the following simple boxplot of penguin body mass grouped by sex using code very similar to the code in your textbook on page 146.
See if you can modify Gardener’s code to create your boxplot of of penguin flipper length grouped by sex.
Note how Gardener’s code uses the formula notation
and the data
argument.
The code in the Gardener book will not work as as it appears in the text!
In order to follow along with the book code, you’ll have to use the
following two parameters in your call to read.csv()
:
check.names = FALSE
row.names = 1
Gardener explains the check.names
parameter, but he does
not mention the row.names
parameter.
Download the butterfly_table.csv
file from the
course GitHub site and save it in the data subdirectory of your
main course folder.
Using read.csv()
read the data into a
data.frame
object called butterfly
in R. Make
sure you read the warning above.
Follow along with the code in the Have a Go: Use R for multiple series bar charts at the end of section 6.3.1 of Gardener chapter 6 to create a barplot.
Adjust the code from step 8 to include a vector of six custom colors.
mycols
from
step 9.terrain.colors()
for
some other color ideas.These questions are for your reference, the same questions will appear in the assignment page on Moodle.
You should do your work outside of Moodle, saving your answers in a document and/or R script file.
When you are ready to submit your answers, you can paste your complete responses in the corresponding Moodle question entries for the assignment.