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 |
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 |
obs |
Name of observation counts in |
normalize |
Should values te normalized to probabilities and expressed in percent? |
full_range |
If |
center_x , center_y , center |
Should a binary x or y variable be centered (axis reversed) so that the spars meet? |
fill_x , fill_y , fill |
Should the space between x or y bars and the axis be filled? |
kite , square , spars , chi2 |
Should the kite, square, spars and |
bars_x , bars_y , bars |
Should the bars for the x and y variables be drawn? |
intersect_x , intersect_y , intersect |
Should the intersect positions for x and y variables with their axes be drawn? |
color_x , color_y |
Colors for x and y. |
kite_color , square_color , spars_color , chi2_color |
Color of the kite, square, spars and |
border_color |
Color for the border around each cell. |
alpha_fill , alpha_chi2 , alpha |
Transparency for fill and |
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 |
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)