Individuals on the plot
Graphical displays of data are almost always useful for exposing patterns in the data, particularly when these are unexpected; this might be of great help in suggesting which class of models might be most sensibly applied in the later more formal analysis.
To begin we shall plot the BPRS values for all 40 men, differentiating between the treatment groups into which the men have been randomized. This simple graph makes a number of features of the data readily apparent.
REMEMBER: In ggplot2
or dplyr
syntax, you generally do not need to "quote" variable names!
This exercise is part of the course
Helsinki Open Data Science
Exercise instructions
- Draw the plot with
week
on the x-axis andbprs
on the y-axis - Inspect the plot. See how both the BPRS-score and the variability between individuals decrease over the eight weeks time
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# dplyr, tidyr packages and BPRSL are available
#Access the package ggplot2
library(ggplot2)
# Draw the plot
ggplot(BPRSL, aes(x = "Change me!", y = "Change me too!", linetype = subject)) +
geom_line() +
scale_linetype_manual(values = rep(1:10, times=4)) +
facet_grid(. ~ treatment, labeller = label_both) +
theme(legend.position = "none") +
scale_y_continuous(limits = c(min(BPRSL$bprs), max(BPRSL$bprs)))