To give you an opportunity to continue practicing your R skills between now and the next workshop session, we have provided a new dataset for you to use, along with some practice problems.
Feel free to refer back to the code you wrote during the first workshop session. It’s very common (and encouraged!) to recycle and modify code you and others have written.
msleep
is a dataset that’s available in R as part of the
ggplot2
pacakge, similar to the complete_old
dataset we have been using from the ratdat
package. The
msleep
dataset has information about different species of
mammals and their sleep habits.
Write and execute the following code to read about where the dataset came from and what the variables are.
?msleep
brainwt
(brain weight) on the x-axis and sleep_total
on the
y-axis.vore
, which indicates the type of diet the animal
has.scale_x_log10
function.Reminders!
- geom_point
is the function used to tell ggplot2 to make a
scatter plot
- alpha =
is how we specify transparency
Your code and the scatter plot you created should look similar to the following:
ggplot(data = msleep,
aes(x = brainwt,
y = sleep_total,
color = vore)) +
geom_point(alpha = 0.8) +
scale_x_log10()
vore
(diet) as
the x variable and awake
(time awake in hours) as the y
variable.vore
(diet)scale_viridis_d
to change the
color scale during the workshop. There is a similar
function called scale_fill_viridis_d
that works very
similarly but operates on the fill variable
instead.Reminder!
- fill =
is how we specify fill color
Your code and the boxplot you created should look similar to the following:
ggplot(data = msleep,
aes(x = vore,
y = awake,
fill = vore)) +
geom_boxplot() +
scale_fill_viridis_d()