Plot first, ask questions later
To begin, we shall ignore the repeated-measures structure of the data and assume that all the observations are independent of one another. Now if we simply ignore that the sets of 11 weights come from the same rat, we have a data set consisting of 176 weights, times, and group memberships that we see can easily be analyzed using multiple linear regression. To begin, we will plot the data, identifying the observations in each group but ignoring the longitudinal nature of the data.
We'll start with a simple plot and continue by adding some styling elements. Feel free to experiment!
This exercise is part of the course
Helsinki Open Data Science
Exercise instructions
- Check the dimensions of RATSL
- Draw the
Weight
againstTime
plot - Add line type aesthetics to differentiate the rat groups by assigning
aes(linetype = Group)
as an argument togeom_line()
- Add x-axis label and breaks by adding
scale_x_continuous(name = "Time (days)", breaks = seq(0, 60, 10))
to the plot. - Add x-axis label by adding
scale_y_continuous(name = "Weight (grams)")
- Change the position of the legend by adding
theme(legend.position = "top")
. - Observe the difference between the weights of the rats in Group 1 and those in the other two groups
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# dplyr, tidyr and RATSL are available
# Check the dimensions of the data
# Plot the RATSL data
ggplot(RATSL, aes(x = Time, y = Weight, group = ID)) +
geom_line()