Free Access Week-  Data Engineering + BI
Data engineering and BI courses are free!
Free AI Access Week from June 2-8

sjPlot (version 1.8.1)

sjp.gpt: Plot grouped proportional tables

Description

Plot grouped proportional crosstables, where the proportion of each level of x for the highest category in y is plotted, for each subgroup of groups.

Usage

sjp.gpt(x, y, groups, geom.colors = "Set1", geom.size = 4,
  shape.fill.color = "#f0f0f0", shapes = c(15, 16, 17, 18, 21, 22, 23, 24,
  25, 7, 8, 9, 10, 12), title = NULL, axisLabels = NULL,
  axisTitle.x = NULL, axisTitle.y = NULL, legendTitle = NULL,
  legendLabels = NULL, breakTitleAt = 50, breakLabelsAt = 15,
  breakLegendTitleAt = 20, breakLegendLabelsAt = 20, axisLimits = NULL,
  gridBreaksAt = NULL, showTotal = TRUE, annotateTotal = TRUE,
  showP = TRUE, showN = TRUE, hideLegend = FALSE, printPlot = TRUE)

Arguments

x
categorical variable, where the proportion of each categorie in the highest category of y will be printed along the x-axis.
y
categorical or numeric variable. If not a binary variable, y will be recoded into a binary variable, dichtomized at the highest category and all remaining categories.
groups
grouping variable, which will define the y-axis
geom.colors
User defined color palette for geoms. If specified, must either be vector with color values of same length as groups defined in varGroup, or a specific color brewer palette code (see 'Note').
geom.size
size resp. width of the geoms (bar width or point size, depending on type argument). Note that bar and bin widths mostly need smaller values than dot sizes (i.e. if type = "dots"). By default, geom.size = NULL, whic
shape.fill.color
optional color vector, fill-color for non-filled shapes
shapes
numeric vector with shape styles, used to map the different categories of x.
title
plot title as string. Example: title = "my title". Use NULL to automatically detect variable names that will be used as title (see set_label) for details). If title =
axisLabels
character vector with groups labels for the y-axis.
axisTitle.x
title for the x-axis. By default, "" is used, i.e. no title is printed. If axisTitle.x = NULL, the variable name will be automatically detected and used as title (see set_label
axisTitle.y
title for the-y axis. By default, "" is used, i.e. no title is printed. If axisTitle.y = NULL, variable name will be automatically detected and used as title (see set_label
legendTitle
title of the plot legend, as string.
legendLabels
a character vector with labels for the guide/legend.
breakTitleAt
determines how many chars of the plot title are displayed in one line and when a line break is inserted into the title.
breakLabelsAt
determines how many chars of the category labels are displayed in one line and when a line break is inserted.
breakLegendTitleAt
determines how many chars of the legend's title are displayed in one line and when a line break is inserted.
breakLegendLabelsAt
determines how many chars of the legend labels are displayed in one line and when a line break is inserted.
axisLimits
numeric vector of length 2, defining the range of the plot axis.
gridBreaksAt
set breaks for the axis, i.e. at every gridBreaksAt'th position a major grid is being printed.
showTotal
logical, if TRUE, a total summary line for all aggregated groups is added.
annotateTotal
logical, if TRUE and showTotal = TRUE, the total-row in the figure will be highlighted with a slightly shaded background.
showP
logical, if TRUE, axis labels for groups will also contain the results of the chisq.test of x and y for each groups.
showN
logical, if TRUE, axis labels for groups will also contain the total number of cases in each groups.
hideLegend
logical, indicates whether legend (guide) should be shown or not.
printPlot
logical, if TRUE (default), plots the results as graph. Use FALSE if you don't want to plot any graphs. In either case, the ggplot-object will be returned as value.

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

Examples

Run this code
library(sjmisc)
data(efc)

# the proportion of dependency levels in female
# elderly, for each family carer's relationship
# to elderly
sjp.gpt(efc$e42dep, efc$e16sex, efc$e15relat)

# proportion of educational levels in highest
# dependency category of elderly, for different
# care levels
sjp.gpt(efc$c172code, efc$e42dep, efc$n4pstu)

Run the code above in your browser using DataLab