ciu.ggplot.contrastive: Create contrastive ggplot

View source: R/ContextualInfluence.R

ciu.ggplot.contrastiveR Documentation

Create contrastive ggplot

Description

Create contrastive ggplot

Usage

ciu.ggplot.contrastive(
  ciu.meta.result,
  contrastive.influences,
  instance.names = NULL,
  question = "Why?",
  negative.color = "firebrick",
  positive.color = "steelblue"
)

Arguments

ciu.meta.result

ciu.meta.result object for the instance to be explained, i.e. the first instance parameter of ciu.contrastive.

contrastive.influences

Contrastive influence values, as normally returned by ciu.contrastive.

instance.names

Vector with the labels to be used for the compared classes/instances. If NULL, then we use c("instance One", "instance Two").

question

What kind of explanation do we answer. Can be "Why?" and "Why not?". Default is "Why?".

negative.color

Color to use for negative influence. Default is firebrick.

positive.color

Color to use for positive influence. Default is steelblue.

Value

ggplot object.

Author(s)

Kary Främling

Examples

library(ciu)
library(MASS)
test.ind <- 100
iris_test <- iris[test.ind, 1:4]
iris_train <- iris[-test.ind, 1:4]
iris_lab <- iris[[5]][-test.ind]
model <- lda(iris_train, iris_lab)
# Create CIU object
ciu <- ciu.new(model, Species~., iris)
# First case: why is this a versicolor and not a virginica?
meta <- ciu$meta.explain(iris_test)
ciuvals.versicolor <- ciu.list.to.frame(meta$ciuvals, out.ind = 2)
ciuvals.virginica <- ciu.list.to.frame(meta$ciuvals, out.ind = 3)
# Now the contrastive part:
contrastive <- ciu.contrastive(ciuvals.versicolor, ciuvals.virginica)
print(ciu.ggplot.contrastive(meta, contrastive, c("Versicolor", "Virginica")))
# Then a "Why not?" explanation
contrastive.neg <- ciu.contrastive(ciuvals.virginica, ciuvals.versicolor)
print(ciu.ggplot.contrastive(meta, contrastive.neg,
  question = "Why not?", c("Virginica", "Versicolor")))

ciu documentation built on June 17, 2025, 1:08 a.m.