-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
66 lines (53 loc) · 2.61 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# ggplot.spaghetti
The goal of `ggplot.spaghetti` is to aid preliminary data investigation into longitudinal/time-series data through visualization. By being able to create plots using different grouping variable, the investigator can have a better idea which variables may be worthwhile to control or include in a hypothesis test. Also these images can be used to help rely to other non-statistical collaborators the trends from a mixed-effects or other type of longitudinal model.
## Installation
You can install ggplot.spaghetti from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("williazo/ggplot.spaghetti")
```
## Example
This is an example using the `Orthodont` data set from the `nlme` package. Children were measured at 8, 10, 12, and 14 years to determine the distance from the pituitary to the pterygomaxillary fissure in millimeters. We can group these time measurements by `Gender`, and I have also created another binary variable, `Race`, to highlight the ability to look at multiple grouping variables at the same time.
```{r example}
library(ggplot.spaghetti)
library(nlme)
data("Orthodont")
Orthodont = data.frame(Orthodont, Race = rep(ifelse(rbinom(n = 27, size = 1, prob = 0.5)==0, "White", "Non-White"), each = 4))
attach(Orthodont)
#specifying just group
ortho_plot_group <- ggplot_spaghetti(y = distance, id = Subject, time = age,
alpha = 0.3, group = Sex, method = "lm")+
xlab("Age (yrs.)")+
ylab("Distance")+
scale_color_grey(name = "Gender", start = 0.0, end = 0.5)+
scale_linetype_manual(name = "Gender", values = c("dashed", "solid"))
ortho_plot_group
#specifying just wrap
ortho_plot_wrap <- ggplot_spaghetti(y = distance, id = Subject, time = age,
alpha = 0.3, wrap = Race, method = "loess")+
xlab("Age (yrs.)")+
ylab("Distance")+
scale_color_grey(name = "Race", start = 0.0, end = 0.5)+
scale_linetype_manual(name = "Race", values = c("dashed", "solid"))
ortho_plot_wrap
#specifying both group and wrap
ortho_plot <- ggplot_spaghetti(y = distance, id = Subject, time = age,
alpha = 0.3, group = Sex, wrap = Race,
method = "glm")+
xlab("Age (yrs.)")+
ylab("Distance")+
scale_color_grey(name = "Gender", start = 0.0, end = 0.5)+
scale_linetype_manual(name = "Race", values = c("dashed", "solid"))
ortho_plot
```