Package {ParallelTree}


Type: Package
Title: Visualizing Multilevel Data with Parallel Tree Plots
Version: 0.2.0
Description: Provides two functions: Group_function() and Parallel_Tree(). Group_function() applies a given function (e.g., mean()) to input variable(s) by group across levels of a multilevel data structure, with additional data management options. Parallel_Tree() uses 'ggplot2' to create parallel coordinate plots (technically a facsimile of parallel coordinate plots in a Cartesian coordinate system). Used in combination, these functions can create parallel tree plots, a variant of parallel coordinate plots useful for visualizing multilevel data.
License: GPL-3
Encoding: UTF-8
Imports: stats, ggplot2
RoxygenNote: 8.0.0
NeedsCompilation: no
Packaged: 2026-05-29 15:24:17 UTC; pgok1
Author: Patrick O'Keefe [aut, cre]
Maintainer: Patrick O'Keefe <pgok15@gmail.com>
Repository: CRAN
Date/Publication: 2026-06-03 14:10:18 UTC

Group_function

Description

Group_function

Usage

Group_function(
  data = NULL,
  x,
  levels,
  func = mean,
  center = FALSE,
  nested = TRUE,
  append = FALSE,
  funcName = "Mean"
)

Arguments

data

a data frame with the x and level variables included. Default is NULL.

x

If data = NULL a dataframe of scores to have the function applied to. If data != NULL, a vector of string(s) naming the variable(s) in data to use.

levels

If data = NULL, a dataframe of grouping variables. If data != NULL, a vector of strings naming the variables in data to use. levels should be ordered from the highest level to the lowest. Group and case identifiers should be unique, if they are not unique, cases with non-unique identifiers will be grouped together.

func

A function to apply at each group. Default is mean.

center

If set to true variables will be group/person mean centered. Note that the grand mean remains unchanged by this operation. If this output is to be passed directly to Parallel_Tree the grand mean should be set to 0.

nested

Are level variables nested? Default is TRUE. If set to FALSE means will be calculated for level variable independently. FALSE may be useful in cases of crossed designs. Note that if data are nested but all identifiers are unique both within and across groups nested = FALSE and nested = TRUE will return the same result.

append

If set to true, the original data will be returned along with all created variables.

funcName

Provides way to name function used. This is used when creating names for created variables. Default is "Mean".

Value

This function returns a dataframe with variables labeled according to the level at which the function was applied. Assumed function is mean, and all variables are labeled accordingly. If an alternative function is used labels should be manually changed to reflect function used.

Examples

#the ChickWeight data is from base R
#nested is set to false because Chick and Time are crossed
Means_Chick<-Group_function(data=ChickWeight,x="weight", levels =c("Diet","Chick","Time"),
nested = FALSE, append=TRUE)

Parallel_Tree

Description

Parallel_Tree

Usage

Parallel_Tree(
  x,
  use = names(x),
  standardize = "NONE",
  full_plot = TRUE,
  append = NULL,
  a = 1,
  type = NULL,
  linesize = 0.1,
  color = NULL
)

Arguments

x

A data frame to be used for plotting. If other arguments are left blank the entire data frame will be plotted.

use

A vector of strings naming the variables, in order, in x to be used for plotting. Default is names(x). Note: Variables can be repeated if desired.

standardize

Asksif variables used should be converted to z-scores ("Z"), or if scales should be set to have identical minimums and maximums ("MM") prior to plotting. Useful when plotted variables are on different scales. Default is "NONE".

full_plot

A logical operator, if set to FALSE, output will be a ggplot2 object with no geoms. Default is TRUE.

append

A vector strings naming variables in x that should be appended to the data frame used for plotting. Default is NULL.

a

The alpha to be used by geom_path() when making the plot. Default is 1, but should be set lower if overplotting is likely to be an issue.

type

allows for two choices: "negative" Sets geom_path() color to "white", and plots on a black background. Second option is "print_friendly" which will produce a plot with plack background only behind observations and the rest of the plot will be white. Designed to retain benefits of plotting white lines on black background while minimizing ink usage, this option may also be useful for simultaneous density observation and outlier detection. Default is NULL.

linesize

allows choice of line size used for geom_path() default is 0.1.

color

takes a string variable to be passed to geom_path() color aesthetic.

Value

The function returns a ggplot with scores on the Y axis and variable names, corresponding to levels, on the X axis. Default uses geom_path to create an individual path for each level 1 score.

Examples

#the ChickWeight data is from base R
#nested is set to false because Chick and Time are crossed
Means_Chick<-Group_function(data=ChickWeight,x="weight", levels =c("Diet","Chick","Time"),
 nested = FALSE, append=TRUE)
#Here all values not plotted are appended to the temp data frame
#created in the Parallel_Tree function
Y<-Parallel_Tree(Means_Chick, use = c("Grand Mean weight", "Diet Mean weight",
"Chick Mean weight","Time Mean weight", "weight"),
append = c("Diet","weight","Time","Chick"))
Y

#color can be added using the color functionality
Z<-Parallel_Tree(Means_Chick, use = c("Grand Mean weight", "Diet Mean weight",
"Chick Mean weight","Time Mean weight", "weight"),
color="Diet")
Z

#altering the alpha, and plotting using the negative setting,
#may be useful in cases of overplotting.
Parallel_Tree(Means_Chick, use = c("Grand Mean weight", "Diet Mean weight",
"Chick Mean weight","Time Mean weight", "weight"),
append = c("Diet","weight","Time","Chick"), a=.2, type="negative")

#geom_path is the default, although other geoms may be useful
## Not run: 
Parallel_Tree(Means_Chick, use = c("Grand Mean weight", "Diet Mean weight",
"Chick Mean weight","Time Mean weight", "weight"),
append = c("Diet","weight","Time","Chick"), full_plot=FALSE) +
ggplot2::geom_boxplot(ggplot2::aes(group=levels))+
ggplot2::scale_x_continuous(breaks=c(1:5),
labels=c("Grand Mean","Diet Mean", "Chick Mean", "Age Mean", "Scores"))

#Note that if facets are used the means are not recalculated.
#Such plots should be interpreted with caution.
Y+ggplot2::geom_path(ggplot2::aes(color=Diet))+ggplot2::facet_wrap(~Time)

## End(Not run)