Description Usage Arguments Value Author(s) References See Also Examples
View source: R/ggplot2.density.R
Easy density plot with R package ggplot2
1 2 3 4 5 |
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. |
a ggplot
Alboukadel Kassambara <alboukadel.kassambara@gmail.com>
http://www.sthda.com
ggplot2.dotplot, ggplot2.violinplot,
ggplot2.stripchart, ggplot2.boxplot, ggplot2.histogram
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.