| densgroups | R Documentation | 
This function plots density lines of subgroups for a given variable
densgroups(x,g,cols,g.levels.order,plot.opt,density.opt,curve.opt,legend=TRUE,legend.opt)
| x | The initial variable | 
| g | The groups variable, must be of same length than  | 
| 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  | 
| plot.opt | Options (as a list) to be passed to the initial  | 
| density.opt | Options (as a list) to be passed to the  | 
| curve.opt | Options (as a list) to be passed to the  | 
| legend | Logical indicating whether a legend for each subgroup has to be drawn | 
| legend.opt | Options (as a list) to be passed to the  | 
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))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.