This article describes how to go from a standard table...
...to a CreateCustomTable R table (similar to a table with Autofit checked) that colors significant cells:
...or a CreateCustomTable R table that shows significant arrows:
Requirements
- A standard table with one or more columns.
Please note these steps require a Displayr license.
Method
1. Select your table.
2. Copy the name from General > GENERAL > Name.
3. Go to the Calculation icon > Custom code.
4. Click onto the page to place the custom calculation.
5. Paste the below under General > R CODE:
#identify mytable
mytable = table.D2.Income.by.D3.Gender
#get statistical info for each cell by row
sigs = attr(mytable,"QStatisticsTestingInfo")$significancedirection
#turn into matrix the same shape as the table
sigs = matrix(sigs, nrow = NROW(mytable), ncol = NCOL(mytable), byrow = T)
#Update sig results to positive and negative values
sigs[sigs == "Down"] = -1
sigs[sigs == "Up"] = 1
#create custom table
flipFormat::CreateCustomTable(mytable,
sig.change.fills = sigs,
col.width = c("40%"),
row.header.align.horizontal = "right",
row.header.pad = 3)
- The above code defines the table using the reference name from step 2.
- Next, we extract the table's significance testing attribute information as an object called sigs to store a 1 if significantly higher and -1 if significantly lower.
- Finally, we use our CreateCustomTable function from the flipFormat R package and parse sigs into the sig.change.fills argument.
6. OPTIONAL: To display arrows instead of color fills, change sig.change.fills to sig.change.arrows.
7. OPTIONAL: To change the fill colors, add the sig.fills.up and sig.fills.down arguments. You can reference colors by name and rgb, e.g. rgb(255,255,255).
8. OPTIONAL: To change the significance arrow colors, add the sig.arrows.up and sig.arrows.down arguments. You can reference colors by name and rgb, e.g. rgb(255,255,255).
9. OPTIONAL: Add other arguments to CreateCustomTable to set colors, padding, and font styles.
Next
How to Customize Fonts in a CreateCustomTable R Table
How to Customize Colors on a CreateCustomTable R Table
How to Add Scrolling to an Autofit or CreateCustomTable R Table
How to Create a CreateCustomTable R Table of Images
How to Add Row Spans to a CreateCustomTable R Table
How to Add Column Spans to a CreateCustomTable R Table