ggplot2.density: Easy density plot with R package ggplot2

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/ggplot2.density.R

Description

Easy density plot with R package ggplot2

Usage

1
2
3
4
5
ggplot2.density(data, xName = NULL, groupName = NULL, addMeanLine = FALSE,
  meanLineColor = NULL, meanLineType = "dashed", meanLineSize = 1,
  densityFill = NULL, fillGroupDensity = FALSE,
  colorGroupDensityLine = FALSE, groupColors = NULL, brewerPalette = NULL,
  ...)

Arguments

data

data.frame or a numeric vector. Columns are variables and rows are observations.

xName

The name of column containing x variable (i.e groups). Default value is NULL.

groupName

The name of column containing group variable. This variable is used to color plot according to the group.

addMeanLine

if TRUE, the mean line is added on the plot for each group. Default value is FALSE.

meanLineColor, meanLineType, meanLineSize

mean line color, type and size.

densityFill

Fill color of density plot. This is only considered when groupName=NULL.

fillGroupDensity

If TRUE, density curve of each group is filled. Default value is FALSE.

colorGroupDensityLine

If TRUE, density curve line are colored. Default value is FALSE.

groupColors

Color of groups. groupColors should have the same length as groups.

brewerPalette

This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette="Paired".

...

Other arguments passed on to ggplot2.customize custom function or to geom_density functions from ggplot2 package.

Value

a ggplot

Author(s)

Alboukadel Kassambara <alboukadel.kassambara@gmail.com>

References

http://www.sthda.com

See Also

ggplot2.dotplot, ggplot2.violinplot, ggplot2.stripchart, ggplot2.boxplot, ggplot2.histogram

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#data
set.seed(1234)
df <- data.frame(grp = factor( rep(c("A","B"), each=200) ),
                   var = c(rnorm(200),rnorm(200, mean=.8)))

#plot
ggplot2.density(data=df, xName='var',groupName='grp', groupColors=c('#999999','#E69F00'),
                mainTitle="Plot of variable histogram \nper group",
                xtitle="Variable", ytitle="Density")

#Or use this
plot<-ggplot2.density(data=df, xName='var',groupName='grp', groupColors=c('#999999','#E69F00'))
plot<-ggplot2.customize(plot, mainTitle="Plot of variable histogram \nper group",
                        xtitle="Variable", ytitle="Density")
print(plot)

kassambara/easyGgplot2 documentation built on May 20, 2019, 7:39 a.m.