In-Class Histograms Intro to Quantitative Ecology:
Your group will submit a single document, but every member of your group needs to create their own markdown document and follow the code in the exercise.
Create a new R Markdown file and name it
in_class_histograms.Rmd
.
palmerpenguins
R PackageOne of the great things about R is that you can extend it by installing packages.
Just use the install.packages()
function.
For this exercise your group will need to install the
palmerpenguins
package, which contains data collected from
3 species of penguin.
install.packages("palmerpenguins")
You only need to install a package once. After the package installs, you should put a comment character at the beginning of the line so that you don’t re-install the package every time!
After you’ve successfully installed a package, you have to tell R to
load it into memory using the library()
or
require()
functions.
require()
:require("palmerpenguins")
Now you’ll have the penguins
data frame loaded into R’s
memory.
Use the head()
function to print the first 6 lines of
the penguins
data frame.
Recall from the DataCamp assignment that you can pull out a named column of a data frame using the dollar sign symbol, followed by the name of the column.
Try it for the body_mass_g
column.
There are 4 numeric columns in the penguins data:
bill_length_mm
bill_depth_mm
flipper_length_mm
body_mass_g
Each member of your group needs to choose one of the columns and build a histogram. If your group has more than 4 members, then two members may choose the same column.
Remember how to use the dollar sign to subset a named column?
Here’s a very basic histogram of body mass
hist(penguins$body_mass_g)
Note:
Each group member needs to plot a histogram of their chosen column, with the following customizations:
Here’s how I could use the main
argument to customize my body length histogram with my
name:
hist(
x = penguins$body_mass_g,
main = "Mike's Histogram of Penguin Mass")
You can also use the xlab
argument to customize the
x-axis name.
See if you can re-create this plot without seeing the code:
If your group finishes all of your histograms early and wants to try
some more histogram customizations, try out some of the other
arguments to hist()
, for example:
Your group will submit an R-script and at least one question for me for discussion on Thursday.
palmerpenguins
package