We built plotrr to inspect relationships within groups
before fitting a model to pooled data. Exploratory data analysis helps
us see the observations and assumptions we’re bringing to an analysis
(Tukey 1977). It can also reveal unusual cases that deserve a closer
look (NIST/SEMATECH 2012).
Here we’ll use simulated data to show how the plotting functions work. The patterns come from the simulation; they aren’t evidence about a population.
As demonstrated in Crabtree and Nelson (2017), group-level plots can help us see whether an expected relationship appears in particular cases. We’d use those patterns to guide further investigation, with the research design still determining what we can say about causes.
bivarplotsbivarplots() prints a scatterplot and smooth curve for
each group. Check how many groups you have first with
lengthunique(); a large dataset can produce a lot of
plots.
library(plotrr)
a <- runif(400, min = 0, max = 1)
b <- a + rnorm(400, mean = 0, sd = 1)
c <- rep(c(1:4), times = 100)
data <- data.frame(a, b, c)
bivarplots("a", "b", "c", data)## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
dotplotsdotplots() prints the distribution of x as stacked dots
for each group. Its y argument is retained for compatibility and is
unused.
library(plotrr)
a <- runif(400, min = 0, max = 1)
b <- a + rnorm(400, mean = 0, sd = 1)
c <- rep(c(1:4), times = 100)
data <- data.frame(a, b, c)
dotplots("a", "b", "c", data, 20)We can use these plots to examine competing measures within groups. Agreement between measures is one part of assessing construct validity (Trochim & Donnelly, 2008). A disagreement in a particular case can also suggest a useful question: what is each measure capturing there?
histplots() prints a histogram of x for each group. Set
n to choose the number of bins; the y argument is
unused.
library(plotrr)
a <- rnorm(400, mean = 2, sd = 100)
b <- a + rnorm(400, mean = 0, sd = 1)
c <- rep(c(1:4), times = 100)
data <- data.frame(a, b, c)
histplots("a", "b", "c", data, 5)bivarrugplot() adds a mark along each axis for every
observed value. The rugs help show where observations are
concentrated.
library(plotrr)
a <- runif(1000, min = 0, max = 1)
b <- a + rnorm(1000, mean = 0, sd =1)
data <- data.frame(a, b)
bivarrugplot("a", "b", data)## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## ℹ The deprecated feature was likely used in the plotrr package.
## Please report the issue at <https://github.com/lobsterbush/plotrr/issues>.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Use of `data[[x]]` is discouraged.
## ℹ Use `.data[[x]]` instead.
## Warning: Use of `data[[y]]` is discouraged.
## ℹ Use `.data[[y]]` instead.
## Warning: Use of `data[[x]]` is discouraged.
## ℹ Use `.data[[x]]` instead.
## Warning: Use of `data[[y]]` is discouraged.
## ℹ Use `.data[[y]]` instead.
lengthunique() counts distinct non-missing values.
makefacnum() reads a factor’s labels as numbers;
non-numeric labels become missing values with a warning.
clear() prints a form-feed character, which clears some
console displays.