Learn R Programming

sjPlot (version 1.7)

sjp.grpfrq: Plot grouped or stacked frequencies

Description

Plot grouped or stacked frequencies of variables as bar/dor graphs, box or violin plots, histograms etc. using ggplot.

Usage

sjp.grpfrq(varCount, varGroup, weightBy = NULL, weightByTitleString = NULL,
  interactionVar = NULL, type = "bars", geom.size = 0.6,
  geom.spacing = 0.4, geom.colors = "Paired", hideLegend = FALSE,
  facet.grid = FALSE, title = "", legendTitle = NULL,
  axisLabels.x = NULL, interactionVarLabels = NULL, legendLabels = NULL,
  axisLimits.y = NULL, breakTitleAt = 50, breakLabelsAt = 15,
  breakLegendTitleAt = 20, breakLegendLabelsAt = 20, gridBreaksAt = NULL,
  barPosition = "dodge", innerBoxPlotWidth = 0.15,
  innerBoxPlotDotSize = 3, smoothLines = FALSE, expand.grid = FALSE,
  showValueLabels = TRUE, showCountValues = TRUE,
  showPercentageValues = TRUE, showAxisLabels.x = TRUE,
  showAxisLabels.y = TRUE, showPlotAnnotation = TRUE,
  showMeanIntercept = FALSE, showMeanValue = TRUE,
  showStandardDeviation = FALSE, showTableSummary = TRUE,
  showGroupCount = FALSE, tableSummaryPos = "r",
  meanInterceptLineType = 2, meanInterceptLineSize = 0.5,
  axisTitle.x = "", axisTitle.y = "", autoGroupAt = NULL,
  startAxisAt = "auto", coord.flip = FALSE, labelPos = "outside",
  na.rm = TRUE, printPlot = TRUE)

Arguments

Value

(Insisibily) returns the ggplot-object with the complete plot (plot) as well as the data frame that was used for setting up the ggplot-object (df).

See Also

  • http://www.strengejacke.de/sjPlot/sjp.grpfrq/{sjPlot manual: sjp.grpfrq}

Examples

Run this code
# histrogram with EUROFAMCARE sample dataset
data(efc)
efc.val <- get_val_labels(efc)
efc.var <- get_var_labels(efc)
sjp.grpfrq(efc$e17age,
           efc$e16sex,
           title = efc.var['e17age'],
           legendTitle = efc.var['e16sex'],
           type = "hist",
           showValueLabels = FALSE,
           showMeanIntercept = TRUE)

# boxplot
sjp.grpfrq(efc$e17age,
           efc$e42dep,
           type = "box")

# -------------------------------------------------
# auto-detection of value labels and variable names
# -------------------------------------------------
efc.var <- get_var_labels(efc)
efc <- set_var_labels(efc, efc.var)
# grouped bars using necessary y-limit
sjp.grpfrq(efc$e42dep,
           efc$e16sex,
           title = NULL)

# box plots with interaction variable
sjp.grpfrq(efc$e17age,
           efc$e42dep,
           interactionVar = efc$e16sex,
           title = paste(efc.var['e17age'],
                         "by",
                         efc.var['e42dep'],
                         "and",
                         efc.var['e16sex']),
           axisLabels.x = efc.val[['e17age']],
           interactionVarLabels = efc.val[['e16sex']],
           legendTitle = efc.var['e42dep'],
           legendLabels = efc.val[['e42dep']],
           type = "box")

# Grouped bar plot ranging from 1 to 28 (though scale starts with 7)
sjp.grpfrq(efc$neg_c_7,
           efc$e42dep,
           showValueLabels = FALSE,
           startAxisAt = 1)
# Same grouped bar plot ranging from 7 to 28
sjp.grpfrq(efc$neg_c_7,
           efc$e42dep,
           showValueLabels = FALSE)

Run the code above in your browser using DataLab