Introduction
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.
Method
1. Right click on your table and select Reference Name.
2. Copy this reference name somewhere to use in your code later.
3. Right click on the Report tree and select Add R Output.
4. Paste the below under Properties > 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.
5. Right click on the R Output and select Calculation Options.
6. Change Exporting > Format > To PowerPoint as Image of R Output. Note that this means you cannot edit the table once it is exported to PowerPoint.
7. OPTIONAL: To display arrows instead of color fills, change sig.change.fills to sig.change.arrows.
8. OPTIONAL: To change the fill colors, add the sig.fills.up and sig.fills.down arguments.
9. OPTIONAL: To change the significance arrow colors, add the sig.arrows.up and sig.arrows.down arguments.
10. OPTIONAL: Add other arguments to CreateCustomTable to set colors, padding and font styles.
Note, you can reference colors by HTML name, HEX, and rgb, e.g. rgb(255,255,255).
See Also
How to Customize a Table using CreateCustomTable in R
How to Customize Fonts in a CreateCustomTable R Table
How to Add Row Spans to a CreateCustomTable R Table
How to Add Column Spans to a CreateCustomTable R Table
How to Customize a Table with Multiple Statistics using CreateCustomTable in R