Learn R Programming

sjPlot (version 1.9.3)

sjp.frq: Plot frequencies of variables

Description

Plot frequencies of a variable as bar graph, histogram, box plot etc.

Usage

sjp.frq(varCount, title = "", weightBy = NULL, weightByTitleString = NULL,
  interactionVar = NULL, sort.frq = "none", type = "bars",
  geom.size = NULL, geom.colors = "#336699", axisLabels.x = NULL,
  interactionVarLabels = NULL, axisLimits.x = NULL, axisLimits.y = NULL,
  breakTitleAt = 50, breakLabelsAt = 20, gridBreaksAt = NULL,
  innerBoxPlotWidth = 0.15, innerBoxPlotDotSize = 3, expand.grid = FALSE,
  showValueLabels = TRUE, showCountValues = TRUE,
  showPercentageValues = TRUE, showAxisLabels.x = TRUE,
  showAxisLabels.y = TRUE, showCI = FALSE, error.bar.color = "darkred",
  showMeanIntercept = FALSE, showMeanValue = TRUE,
  showStandardDeviation = TRUE, showNormalCurve = FALSE,
  showStandardNormalCurve = FALSE, adjustNormalCurve.x = FALSE,
  meanInterceptLineType = 2, meanInterceptLineSize = 0.5,
  normalCurveColor = "red", normalCurveSize = 0.8, normalCurveAlpha = 0.4,
  axisTitle.x = NULL, axisTitle.y = NULL, autoGroupAt = NULL,
  coord.flip = FALSE, vjust = "bottom", hjust = "center",
  y.offset = NULL, 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 (mydf).

See Also

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

Examples

Run this code
# boxplot
sjp.frq(ChickWeight$weight, type = "box")

# histogram
sjp.frq(discoveries, type = "hist", showMeanIntercept = TRUE)
        
# violin plot
sjp.frq(ChickWeight$weight, type = "v")

# bar plot
sjp.frq(ChickWeight$Diet)


# bar plot with EUROFAMCARE sample dataset
# dataset was importet from an SPSS-file, using:
# efc <- sjmisc::read_spss("efc.sav", enc = "UTF-8")
library(sjmisc)
data(efc)
# you may use sjp.setTheme here to change axis textangle
sjp.frq(efc$e15relat)

# bar plot with EUROFAMCARE sample dataset
# grouped variable
ageGrp <- group_var(efc$e17age)
ageGrpLab <- group_labels(efc$e17age)
sjp.frq(ageGrp,
        title = get_label(efc$e17age),
        axisLabels.x = ageGrpLab)


# box plots with interaction variable
# the following example is equal to the function call
# sjp.grpfrq(efc$e17age, efc$e16sex, type = "box")
sjp.frq(efc$e17age,
        title = paste(get_label(efc$e17age), 
                      "by", 
                      get_label(efc$e16sex),
        interactionVar = efc$e16sex,
        interactionVarLabels = get_labels(efc$e16sex),
        type = "box"))


# negative impact scale, ranging from 7-28
sjp.frq(efc$neg_c_7)


# plotting confidence intervals
sjp.frq(efc$e15relat,
        type = "dots",
        showCI = TRUE,
        sort.frq = "desc",
        coord.flip = TRUE,
        expand.grid = TRUE, # for text labels
        vjust = "bottom",   # for text labels
        hjust = "left")     # for text labels


# Simulate ggplot-default histogram
sjp.frq(efc$c160age, 
        type = "h", 
        geom.size = 3)

# histogram with overlayed normal curves
sjp.frq(efc$c160age,
        type = "h",
        showMeanIntercept = TRUE,
        showMeanValue = TRUE,
        showNormalCurve = TRUE,
        showStandardDeviation = TRUE,
        showStandardNormalCurve = TRUE,
        normalCurveColor = "blue",
        normalCurveSize = 3,
        axisLimits.y = c(0,50))

Run the code above in your browser using DataLab