Learn R Programming

psych (version 1.8.3.3)

densityBy: Create a 'violin plot' or density plot of the distribution of a set of variables

Description

Among the many ways to describe a data set, one is density plot for each value of a grouping variable and another is violin plot of multiple variables. A density plot shows the density for different groups to show effect sizes. A violin plot is similar to a box plot but shows the actual distribution. Median and 25th and 75th percentile lines are added to the display. If a grouping variable is specified, violinBy will draw violin plots for each variable and for each group.

Usage

violinBy(x,var=NULL,grp=NULL,grp.name=NULL,ylab="Observed",xlab="",main="Density plot",
alpha= 1,adjust=1,restrict=TRUE,xlim=NULL,add=FALSE,col=NULL,pch=20,scale=NULL,...) 
 
densityBy(x,var=NULL,grp=NULL,freq=FALSE,col=c("blue","red","black"),alpha=.5,adjust=1,
 xlab="Variable", ylab="Density",main="Density Plot")

Arguments

x

A matrix or data.frame

var

The variable(s) to display

grp

A grouping variable

grp.name

If the grouping variable is specified, then what names should be give to the group? Defaults to 1:ngrp

ylab

The y label

xlab

The x label

main

Figure title

alpha

A degree of transparency (0=transparent ... 1 not transparent)

adjust

Allows smoothing of density histograms when plotting variables like height

freq

if TRUE, then plot frequencies (n * density)

restrict

Restrict the density to the observed max and min of the data

xlim

if not specified, will be .5 beyond the number of variables

add

Allows overplotting

col

Allows for specification of colours. The default for 2 groups is blue and red, for more group levels, rainbows.

pch

The plot character for the mean is by default a small filled circle. To not show the mean, use pch=NA

scale

If NULL, scale the widths by the square root of sample size, otherwise scale by the value supplied.

Other graphic parameters

Value

The density (y axis) by value (x axis) of the data (for densityBy) or a violin plot for each variable (perhaps broken down by groups)

Details

Describe the data using a violin plot. Change alpha to modify the shading. The grp variable may be used to draw separate violin plots for each of multiple groups.

See Also

describe, describeBy and statsBy for descriptive statistics and error.bars error.bars.by and bi.bars for graphic displays

Examples

Run this code
# NOT RUN {
violinBy(bfi[1:5])
violinBy(bfi,var=1:5,grp ="gender",grp.name=c("M","F"))
densityBy(sat.act,"SATV","gender")
  
# }

Run the code above in your browser using DataLab