densgroups: Multi-subgroup density lines

View source: R/densgroups.R

densgroupsR Documentation

Multi-subgroup density lines

Description

This function plots density lines of subgroups for a given variable

Usage

densgroups(x,g,cols,g.levels.order,plot.opt,density.opt,curve.opt,legend=TRUE,legend.opt)

Arguments

x

The initial variable

g

The groups variable, must be of same length than x

cols

The colors of the different variable lines. By default using the first colors of the [ULT:contrasting.palette] function

g.levels.order

Optional. The order of the levels for the variable g if different from the default one

plot.opt

Options (as a list) to be passed to the initial plot function, that sets the global plot frame. By default set to list(xlab=NA,ylab=NA)

density.opt

Options (as a list) to be passed to the density function used to compute the density.

curve.opt

Options (as a list) to be passed to the lines function used to draw the density lines. By default set to list(lwd=2)

legend

Logical indicating whether a legend for each subgroup has to be drawn

legend.opt

Options (as a list) to be passed to the legennd function if a legend is called. By default set to list("x"="topleft",lwd=2,bty="n",legend=levels(g))

Examples

set.seed(1)
means<-runif(5,-20,20)
sds<-runif(5,0.5,3)
x<-c()
for(i in 1:5){x<-c(x,rnorm(100,means[i],sds[i]))}
g<-as.factor(rep(letters[1:5],each=100))
densgroups(x,g) # Default plot
densgroups(x,g,legend.opt=list(x="topleft")) # Default plot changing location of legend
densgroups(x,g, # With some customization
           cols=c("red","blue","brown","pink","cyan"),
           plot.opt=list(xlab="value",ylab=NA,yaxt="n"),
           curve.opt=list(lwd=3,lty=2),
           legend.opt=list("x"="topright",lwd=2,lty=2,bty="n",legend=paste0(levels(g),", mu=",round(means,2),", sd=",round(sds,2))))


jacobmaugoust/ULT documentation built on May 16, 2023, 1:29 p.m.