Skip to contents

This function creates a scatter plot of the results from a blackbox analysis. It allows for optional grouping of data points and the inclusion of issue vectors based on ordinal regression.

Usage

plot_blackbox(
  result,
  dims,
  whichRes = NULL,
  groupVar = NULL,
  issueVector = NULL,
  data = NULL,
  missing = NULL,
  rug = FALSE,
  xlab = NULL,
  main = NULL,
  ylab = NULL,
  nudgeX = NULL,
  nudgeY = NULL,
  ...
)

Arguments

result

A list object containing the results of the blackbox analysis. This object should include individual-level data for each dimension.

dims

A numeric vector of length 2 indicating the dimensions to plot.

whichRes

An optional integer specifying which result set to use from the result$individuals list. If NULL, the highest dimension is used.

groupVar

An optional vector for grouping the data points. If NULL, no grouping is applied.

issueVector

A vector indicating which issues to include as vectors in the plot. This can be a character vector of column names or a numeric vector of column indices.

data

A data frame containing the original data used in the analysis. Required if issueVector is specified.

missing

A vector of values to be treated as missing in the data.

rug

Logical, if TRUE, adds marginal rugs to the plot.

xlab

A character string for the x-axis label. If NULL, the label is generated automatically.

main

A character string for the plot title. If NULL, no title is added.

ylab

A character string for the y-axis label. If NULL, the label is generated automatically.

nudgeX

A numeric vector for nudging the x positions of the issue vector labels. Defaults to NULL.

nudgeY

A numeric vector for nudging the y positions of the issue vector labels. Defaults to NULL.

...

Additional arguments passed to ggplot2 functions.

Value

A ggplot2 object representing the blackbox analysis plot.

Examples

if (FALSE) { # \dontrun{
# CDS2000 is a dataset containing U.S. Congressional data,
# where the first column represents party affiliation: 1 for Democrats, 2 for Republicans.

# Recode the party variable: 1 = 'Democrat', 2 = 'Republican', others as NA
party <- car::recode(CDS2000[,1],
                     "1='Democrat'; 2='Republican'; else=NA",
                     as.factor=TRUE)

# Create a Blackbox plot to compare the distribution of different parties in a two-dimensional space
plot_blackbox(result.repdem, dims=c(1, 2), groupVar=party,
              xlab="First Dimension\n(Left-Right)",
              ylab="Second Dimension") +
  theme(legend.position="bottom", aspect.ratio=1) +
  guides(shape=guide_legend(override.aes=list(size=4))) +
  labs(colour="Party")
} # }