Skip to contents

Density plot by group

Usage

plot_density(
  df,
  value,
  group,
  group2 = NA,
  title = NA,
  pval = T,
  xlab = value,
  colors = c("firebrick3", "gray"),
  rug = F,
  rug_label = F,
  rug_lab_nudge = 1e-05,
  savename = NA,
  width = 6,
  height = 4
)

Arguments

df

dataframe

value

string; colname of values

group

string; colname of group info

group2

string; group of interest

title

string; plot title

pval

logical; get KSpval first group vs others

xlab

string; x-axis label

colors

vector; # of colors = to # of groups

rug

logical; put rug plot on x axis

rug_label

logical; label rug ticks with first df column

rug_lab_nudge

numeric; fine-tune distance of label from x-axis

savename

string; filepath to save PNG under

width

numeric; ggsave width of plot

height

numeric; ggsave height of plot

Value

Density plot by group

Examples

set.seed(13)
df = data.frame(
  group = c(rep("A", 50), rep("B",50)),
  values = c(rnorm(50, mean = 0), rnorm(50, mean = 2)))
plot_density(df, value = "values", group = "group")