grottaBar | R Documentation |
Automates the production of a Grotta Bar using ggplot()
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, ... )
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 ( |
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 |
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 |
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"
A ggplot object, or a list containing a ggplot object and the data used to generate it.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.