ggplot2.histogram: Easy histogram plot with R package ggplot2

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

Description

Easy histogram plot with R package ggplot2

Usage

1
2
3
4
5
6
7
8
ggplot2.histogram(data, xName = NULL, groupName = NULL,
  position = c("identity", "stack", "dodge"), addMeanLine = FALSE,
  meanLineColor = NULL, meanLineType = "dashed", meanLineSize = 1,
  addDensityCurve = FALSE, densityFill = "#FF6666", densityAlpha = 0.2,
  densityLineType = "solid", densityLineColor = "#2F2F2F",
  scale = c("frequency", "density"), groupColors = NULL,
  brewerPalette = NULL, fill = "black", color = "black",
  linetype = "solid", ...)

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.

position

Change the position adjustment to use for overlapping points on the layer. Possible values for the argument position is "identity", "stack", "dodge". Default value is identity.

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.

addDensityCurve

If true, add density curve. Default value is FALSE.

densityFill

The fill color of density plot. The value is considered only when groupName=NULL. If groupName is specified, density curves are colored according groupColors pr brewerPalette.

densityAlpha

Degre of transparency of overlaid colors for density curves. Default is 0.2 (20%).

densityLineType, densityLineColor

Line type and color for density curve.

scale

Indicate whether y axis values are density or frequency. Default value is frequency.

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".

linetype, fill, color

linetype, outline and fill colors

...

Other arguments passed on to ggplot2.customize custom function or to geom_histogram and 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.density

Examples

1
2
3
4
5
6
7
8
9
#data
set.seed(1234)
df <- data.frame(grp = factor( rep(c("A","B"), each=200) ), 
                   var = c(rnorm(200),rnorm(200, mean=.8)))
#plot
plot<-ggplot2.histogram(data=df, xName='var',groupName='grp', groupColors=c('#999999','#E69F00'))
plot<-ggplot2.customize(plot, mainTitle="Plot of variable histogram \nper group",
                        xtitle="Variable", ytitle="Histogram")
print(plot)

YTLogos/easyGgplot2 documentation built on May 3, 2019, 9:03 p.m.