Package 'rankinPlot'

Title: Convenient Plotting for the Modified Rankin Scale and Other Ordinal Outcome Data
Description: Provides convenient tools for visualising ordinal outcome data following the "Grotta Bar" approach pioneered by The National Institute of Neurological Disorders and Stroke rt-PA Stroke Study Group (1995) <doi:10.1056/NEJM199512143332401>.
Authors: Hannah Johns [aut, cre]
Maintainer: Hannah Johns <[email protected]>
License: GPL (>=2.0)
Version: 1.1.0
Built: 2025-02-04 03:50:36 UTC
Source: https://github.com/hannahjohns/rankinplot

Help Index


Effect of time to treatment on efficacy of rt-PA in treating acute stroke

Description

A dataset reconstructing reported outcomes after stroke as reported in Lees et. al. (2010) which pooled the results of several studies.

Usage

alteplase

Format

A data frame with 3669 rows and 3 variables:

time

Time interval (minutes) between stroke onset and treatment

treat

Type of treatment received

mRS

Outcome at 3 months measured using the modified Rankin Scale

References

Lees, K. R., Bluhmki, E., Von Kummer, R., Brott, T. G., Toni, D., Grotta, J. C., Albers, G. W., Kaste, M., Marler, J. R., Hamilton, S. A., Tilley, B. C., Davis, S. M., Donnan, G. A., Hacke, W. (2010). Time to treatment with intravenous alteplase and outcome in stroke: an updated pooled analysis of ECASS, ATLANTIS, NINDS, and EPITHET trials. The Lancet, 375(9727), 1695-1703.


grottaBar

Description

Automates the production of a Grotta Bar using ggplot()

Usage

grottaBar(x,groupName,scoreName,strataName = NULL,
          colorScheme="lowGreen",
          printNumbers = "count",
          nCol = 1, dir = "v",
          width = 0.9,
          textSize = 15, numberSize = 5,
          textFace = "plain",
          textColor = "black", textCut = 0,
          lineSize = 0.5,
          returnData = FALSE,
          ...
)

Arguments

x

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

groupName

a character string giving the name of the group varialble

scoreName

a character string giving outcome (mRS) labels

strataName

a character string giving the strata variable name

colorScheme

a character string indicating the colors that should be used by the plot

printNumbers

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

nCol

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

dir

a character indicating if stratified results should be laid out vertically ("v") or horizontally "h".

width

a number adjusting the width of the lines between bars

textSize

a number indicating the size of text labels

numberSize

a number indicating the size of printed numbers

textFace

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

textColor

vector of two colors for text labels

textCut

Controls when the color of the text changes. The first textCut categories will use the first color

lineSize

a number indicating the thickness of lines in the plot

returnData

a boolean indicating if the data used to create the plot should be returned. For expert users only.

...

additional arguments. Ignored except for colourScheme and textColour which will override their counterpart arguments.

Details

This tool produces a "Grotta" bar chart based on a table of count data. A Grotta bar chart is a common data visualisation tool in stroke research, and is in essence a horizontally stacked proportional bar chart showing the distribution of ordinal outcome data (typically the modified Rankin Scale) across groups, with lines drawn connecting categories across groups.

The tool provides three default options for colorScheme:

  • "lowGreen" A "traffic light" gradient from green to red, where low scores are colored green

  • "lowRed" A "traffic light" gradient from red to green, where low scores are colored red

  • "grayscale" A grayscale gradient for producing a black and white plot

In addition to these, setting colorScheme="custom" allows for a user-specified color scheme by using the ggplot2 family of scale_fill_ functions.

The options for printNumbers 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" 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, or a list containing a ggplot object and the data used to generate it.

Examples

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

grottaBar(x,groupName="Group",
          scoreName = "mRS",
          strataName="Time",
          colorScheme ="lowGreen"
 )

  grottaBar(x,groupName="Time",
          scoreName = "mRS",
          strataName="Group",
          colorScheme ="grayscale"
 )

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

   grottaBar(x,groupName="Group",
             scoreName = "mRS",
             colorScheme ="custom"
   ) + ggplot2::scale_fill_brewer(palette = "Spectral", direction=-1)

  grottaBar(x,groupName="Group",
          scoreName = "mRS",
          colorScheme ="custom",
          textFace = "italic",
          printNumbers = "count.percentage"
 ) + viridis::scale_fill_viridis(discrete = TRUE,direction = -1)


grottaBar(
          x,
          groupName = "Group",
          scoreName = "mRS",
          colorScheme = "custom",
          textFace = "italic",
          printNumbers = "count.percentage"
) + viridis::scale_fill_viridis(discrete = TRUE, direction = -1)


grottaBar(x,groupName="Group",
           scoreName = "mRS",
           colorScheme ="custom",
           textFace = "italic",
           textColor = c("black","white"),
           textCut = 5,
           printNumbers = "count.percentage"
) + viridis::scale_fill_viridis(discrete = TRUE,direction = -1)