plot_density_ternary: plot_density_ternary: Plot data density on a ternary plot

View source: R/simplex_plotting.R

plot_density_ternaryR Documentation

plot_density_ternary: Plot data density on a ternary plot

Description

Plot data density on a ternary plot.

Usage

plot_density_ternary(
  data,
  groups = NULL,
  parts_to_plot = NULL,
  n_bins = 5,
  mark_points = NULL,
  theme = NULL,
  transparency = 0.2,
  suppress_legend = FALSE
)

Arguments

data

Data frame containing data to be plotted.

groups

If plotting groups separately, name of the variable in the data frame which identifies the groups to be plotted. This variable should be a factor variable.

parts_to_plot

Names of the three variables in the data frame which are to be plotted on the ternary plot. Note they should be on the same scale (they don't need to be normalised to 1).

n_bins

Number of bins to use on density plot.

mark_points

Points should be the rows of a data frame with the elements of parts_to_plot as columns names. If a groups argument is given, it should also have a column for this (if the groups aren't relevant to the point in a certain row, this can be set as NA).

theme

Optional theme argument which can be set as a ggplot2::theme object and will control how the plot appears.

transparency

Control the transparency of plots. Should be between 0 and 1.

suppress_legend

Suppress legend on plot. May be used when combining plots.

Details

This is a wrapper for ggtern.

Value

Plot showing density of data on ternary plot.

Examples

simdata$activity <- simdata$vigorous + simdata$moderate + simdata$light

plot_density_ternary(data = simdata,
parts_to_plot = c("activity", "sedentary", "sleep"),
n_bins = 10 # This argument specifies we want to use 10 bins
# (i.e. 9 equi-density contours will be plotted between the minimum and maximum
# probability density.) Default is n_bins = 5.
)

OxWearables/epicoda documentation built on Dec. 7, 2022, 9:07 p.m.