pp_plot: pp_plot

View source: R/pp_plot.R

pp_plotR Documentation

pp_plot

Description

Creates probability-probability plots for visualizing all-to-all comparisons of ranked data across two groups

Usage

pp_plot(x,
        groupName,
        scoreName,
        strataName = NULL,
        reverse.scores = FALSE,
        panel = TRUE,
        panel.nCol = NULL,
        panel.dir = "h",
        polygon = panel,
        polygon.alpha = 0.4,
        polygon.color = "#999999",
        polygon.win.fill = "#71f594",
        polygon.tie.fill = "#e8e156",
        polygon.loss.fill= "#f97194",
        contour = FALSE,
        contour.color = "#555555",
        contour.line.color = contour.color,
        contour.label.color = contour.color,
        confint = TRUE,
        confint.angle = "fixed",
        confint.level = 0.95,
        bar = TRUE,
        bar.colorScheme = "Blues",
        bar.colorScheme.reverse = FALSE,
        bar.width = 0.1,
        bar.lineColor = "black",
        bar.linewidth =  0.5,
        bar.text = "count",
        bar.text.size = 5,
        bar.text.color = NULL,
        bar.text.face = "plain",
        neutral.color = "#222222",
        neutral.linetype = "dashed",
        neutral.linewidth = 0.5,
        line.color = NULL,
        line.linetype = "solid",
        strata.text.size = bar.text.size,
        ...
        )

Arguments

x

a 2- or 3- dimensional table, returned by the table() function

groupName

a character string giving the name of the group variable

scoreName

a character string giving outcome labels

strataName

a character string giving the strata variable name

reverse.scores

a logical indicating if the order of the scores should be reversed on the plot

panel

a logical indicating if strata should be separated across panels. If true, returns a faceted plot. If false, all strata are condensed into a single panel.

panel.nCol

an integer indicating the number of columns to use for displaying stratified results. Has no effect if no stratification is used or panel is false.

panel.dir

a character indicating if stratified results should be laid out vertically ("v") or horizontally "h". Has no effect if no stratification is used or panel is false.

polygon

A logical indicating if polygons should be drawn to show the proportion of pairs that are wins, losses or ties. Cannot be used if there are strata and panel is false.

polygon.alpha

A numeric value for the transparency (alpha) for the polygons.

polygon.color

A character string giving the border color for the polygons.

polygon.win.fill

A character string giving the fill color for the polygons indicating a region of wins.

polygon.tie.fill

A character string giving the fill colour for the polygons indicating a region of tied pairs.

polygon.loss.fill

A character string giving the fill colour for the polygons indicating a region of losses.

contour

A logical indicating if contours should be drawn indicating where the probability-probability plot should sit if the proportional odds assumption is met.

contour.color

A character string giving the color of the contours

contour.line.color

A character string giving the color of the contour lines

contour.label.color

A character string giving the color of the contour text

confint

A logical indicating if confidence intervals representing should be drawn around each point. See details.

confint.angle

A character string indicating the direction to draw the angle. See details.

confint.level

A numeric value indicating the level of confidence for the confidence interval.

bar

A logical indicating if bars should be drawn to indicate the distribution of the outcome in each group and strata.

bar.colorScheme

A character string indicating the colour scheme to use for the bars. See details.

bar.colorScheme.reverse

A logical indicating if the colour scheme should be reversed.

bar.width

A numeric value indicating the width of the bars

bar.lineColor

A character string indicating the colour of the bar borders.

bar.linewidth

A numeric value indicating the width of the bar borders.

bar.text

a character string indicating if numbers should be printed for each category.

bar.text.size

a number indicating the size of text labels

bar.text.color

A vector of colors for text labels

bar.text.face

A character string indicating font face of printed numbers. Can be "plain", "bold", "italic" or "bold.italic".

neutral.color

A character string indicating the color of the neutral line

neutral.linetype

A character string indicating the line type of the neutral line

neutral.linewidth

A numeric value indicating the width of the neutral line

line.color

A character string indicating the colour to draw the probability-probability line with, or a discrete color scale returned by ggplot2 to have this vary by strata.

line.linetype

A character string indicating the linetype to draw the probability-probability line with, or a discrete linetype scale returned by ggplot2 to have this vary by strata.

strata.text.size

A number indicating the size of the text to draw the strata label. Only relevant if data is stratified and panel is false.

...

Any other arguments. Ignored, but used to catch e.g. British spelling of "color".

Details

Confidence intervals are estimated using Fisher's exact test and correspond to an odds ratio. They are visually represented as segments on the figure, where the start and end points correspond to cumulative probabilities that match the upper/lower bound of the odds ratio. Two options are given for the direction of these lines. "fixed" indicates that all confidence intervals should be drawn at 45 degrees, while "proportional.odds" indicates that they should be drawn perpendicular to the proportional odds contour line.

bar.colorScheme supports all color schemes from ColorBrewer. See [https://colorbrewer2.org](https://colorbrewer2.org) for more information, or run RColorBrewer::display.brewer.all() to display available options. If the number of categories exceeds what is provided by ColorBrewer, additional values are interpolated as needed.

In addition, setting colorScheme to a ggplot2 discrete scale (e.g. ggplot2::scale_fill_brewer() allows for a user-specified color scheme using the ggplot2 family of scale_fill_ functions.

The options for bar.text are:

"count"

The raw counts in the table.

"proportion"

The within-group proportion, rounded to 2 decimal places.

"percentage"

The within-group percentage, rounded to 2 decimal places.

"count.percentage"

The raw count with percentage in parentheses.

"none", FALSE, NULL or NA

Do not print any numbers.

These options may be abbreviated. "p" is not a valid abbreviation as it matches to multiple options. The minimal abbreviation for "count.percentage" is "c.p"

Value

A ggplot object containing the plot.

References

Johns, Hannah, et al. "Practical guidance for Win Statistics and Tournament Methods for multifaceted outcomes in stroke research: Review and recommendations." International Journal of Stroke (2026) DOI: https://doi.org/10.1177/17474930261475853

Examples


df <- alteplase

x <- table(mRS=df$mRS,
          Group=df$treat,
          Time=df$time)

pp_plot(x,
       groupName =  "Group",
       scoreName = "mRS",
       strataName = "Time",
       panel = TRUE,
       confint = TRUE
)


pp_plot(x,
       groupName =  "Group",
       scoreName = "mRS",
       strataName = "Time",
       panel = FALSE,
       confint = FALSE
)


df <- remapcap
df <- df[which(df$group %in% c("uc","shock")),]
df$group <-droplevels(df$group)

x <- table(Score=df$score,
          Group=df$group
)



pp_plot(x,groupName="Group",
       scoreName = "Score",
       reverse.scores = TRUE,
       bar.text = FALSE,
       confint.angle = "fixed",
       bar.colorScheme = "RdBu",
       bar.colorScheme.reverse = TRUE
)

# Visually inspect proportional odds assumption
pp_plot(x,groupName="Group",
       scoreName = "Score",
       reverse.scores = TRUE,
       bar.text = FALSE,
       confint.angle = "proportional.odds",
       bar.colorScheme = "RdBu",
       bar.colorScheme.reverse = TRUE,
       contour = TRUE,
       polygon = FALSE,
       neutral.color = "darkred", neutral.linewidth =1
)



# Transform the data for comparison of two arms against a common control arm

df_shock <- remapcap[which(remapcap$group %in% c("uc","shock")),]
df_fixed <- remapcap[which(remapcap$group %in% c("uc","fixed")),]

df_shock$group2 <- ifelse(df_shock$group=="uc","Usual Care","Intervention")
df_fixed$group2 <- ifelse(df_fixed$group=="uc","Usual Care","Intervention")
df_shock$intervention <- "Shock"
df_fixed$intervention <- "Fixed"

df <- rbind(df_shock,df_fixed)
df$group2 <- factor(df$group2,levels=c("Usual Care","Intervention"))


x <- table(Score=df$score,
          Group=df$group2,
          Intervention=df$intervention
)



pp_plot(x,groupName="Group",
       scoreName = "Score",
       strataName = "Intervention",
       reverse.scores = TRUE,
       bar.text = FALSE,
       confint= FALSE,
       panel=FALSE,
       bar.colorScheme = "RdBu",
       bar.colorScheme.reverse = TRUE
)

rankinPlot documentation built on Oct. 9, 2026, 5:06 p.m.