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.
violin(x,data=NULL,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,...)
violinBy(x,var=NULL,grp=NULL,data=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,data=NULL,freq=FALSE,col=c("blue","red","black"),alpha=.5,
adjust=1,xlab="Variable", ylab="Density",main="Density Plot")
A matrix or data.frame (can be expressed in formula input)
The variable(s) to display
The grouping variable(s)
The name of the data object if using formula input
If the grouping variable is specified, then what names should be give to the group? Defaults to 1:ngrp
The y label
The x label
Figure title
A degree of transparency (0=transparent ... 1 not transparent)
Allows smoothing of density histograms when plotting variables like height
if TRUE, then plot frequencies (n * density)
Restrict the density to the observed max and min of the data
if not specified, will be .5 beyond the number of variables
Allows overplotting
Allows for specification of colours. The default for 2 groups is blue and red, for more group levels, rainbows.
The plot character for the mean is by default a small filled circle. To not show the mean, use pch=NA
If NULL, scale the widths by the square root of sample size, otherwise scale by the value supplied.
Other graphic parameters
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)
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.
describe
, describeBy
and statsBy
for descriptive statistics and error.bars
error.bars.by
and bi.bars
for graphic displays
# NOT RUN {
violin(psychTools::bfi[1:5])
violin(SATV + SATQ ~ gender, data=sat.act, grp.name =cs(M,F)) #formula input
violinBy(psychTools::bfi,var=1:5,grp ="gender",grp.name=c("M","F"))
densityBy(SATV ~ gender,data =sat.act) #formula input
# }
Run the code above in your browser using DataLab