The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Title: Visualize Contingency Tables Using Kite-Square Plots
Version: 0.0.2
Description: Create a kite-square plot for contingency tables using 'ggplot2', to display their relevant quantities in a single figure (marginal, conditional, expected, observed, chi-squared). The plot resembles a flying kite inside a square if the variables are independent, and deviates from this the more dependence exists.
License: LGPL (≥ 3)
Encoding: UTF-8
URL: https://github.com/HUGLeipzig/kitesquare
BugReports: https://github.com/HUGLeipzig/kitesquare/issues
RoxygenNote: 7.3.2
VignetteBuilder: quarto
Imports: tidyr, dplyr, ggplot2, ggh4x, scales, rlang
Suggests: knitr, quarto
Config/Needs/website: quarto
NeedsCompilation: no
Packaged: 2025-03-19 12:42:45 UTC; Wiedenhoef
Author: John Wiedenhöft ORCID iD [aut, cre, cph]
Maintainer: John Wiedenhöft <john.wiedenhoeft@medizin.uni-leipzig.de>
Repository: CRAN
Date/Publication: 2025-03-20 13:50:09 UTC

Create a kite-square plot

Description

Given a data frame or tibble, creates a kite-square plot to visualize the contingency table of two discrete variables.

Usage

kitesquare(
  df,
  x,
  y,
  obs,
  normalize = FALSE,
  full_range = FALSE,
  center_x = TRUE,
  center_y = TRUE,
  center = NULL,
  fill_x = FALSE,
  fill_y = FALSE,
  fill = NULL,
  kite = TRUE,
  spars = TRUE,
  square = TRUE,
  chi2 = TRUE,
  bars_x = TRUE,
  bars_y = TRUE,
  bars = NULL,
  intersect_x = TRUE,
  intersect_y = TRUE,
  intersect = NULL,
  color_x = "#e31a1c",
  color_y = "#1f78b4",
  kite_color = "black",
  square_color = "black",
  spars_color = "black",
  chi2_color = "#bebebe",
  border_color = "black",
  alpha_fill = 0.3,
  alpha_chi2 = 0.3,
  alpha = NULL,
  pointsize = 3,
  linewidth = 1,
  whisker_length = 0.05,
  extend_whiskers = FALSE,
  dodge_x = 2,
  ...
)

Arguments

df

A tibble or data frame of observations.

x, y

Name of the variable in df for x (columns) and y (rows), as string or expression.

obs

Name of observation counts in df. If a combination of y and x appears multiple times in df, obs are added together. If not provided, a value of 1 will be assumed for each line in df.

normalize

Should values te normalized to probabilities and expressed in percent?

full_range

If normalize is TRUE, should all axes limits be from 0 to 1?

center_x, center_y, center

Should a binary x or y variable be centered (axis reversed) so that the spars meet? center overrides both.

fill_x, fill_y, fill

Should the space between x or y bars and the axis be filled? fill overrides both.

kite, square, spars, chi2

Should the kite, square, spars and \chi^2 patches be drawn?

bars_x, bars_y, bars

Should the bars for the x and y variables be drawn? bars overrides both.

intersect_x, intersect_y, intersect

Should the intersect positions for x and y variables with their axes be drawn? intersect overrides both.

color_x, color_y

Colors for x and y.

kite_color, square_color, spars_color, chi2_color

Color of the kite, square, spars and \chi^2 patches.

border_color

Color for the border around each cell.

alpha_fill, alpha_chi2, alpha

Transparency for fill and \chi^2 patches. alpha overrides both.

pointsize

The point size for intersects and spars.

linewidth

The line width for bars and spars.

whisker_length

The length of bar whiskers.

extend_whiskers

Should the bar whiskers be extended to wrap around the \chi^2 patches?

dodge_x

The number of levels the x axis labels should dodge.

...

Further arguments passed to ggplot2::facet_grid().

Value

A ggplot object, with an extra $table key. The latter contains the tibble of coordinates created internally for plotting.

Examples

df <- dplyr::tibble(
  X=c('A', 'A', 'B', 'B', 'B'),
  Y=c('U', 'V', 'U', 'V', 'V'),
  count=c(30,15,30,70,65))
kitesquare(df, X, Y, count)
kitesquare(df, X, Y, count, normalize=TRUE, center_x=FALSE)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.