Introduction
This article describes how to customize the fonts shown in CreateCustomTable R Tables. The article explains the steps required to go from a standard table looking like this...
...to a custom table with specific fonts used for different parts of the table looking like this:
And also a table where the font dynamically changes based on the data shown...
Requirements
- A table of data to a format. Click here to get a copy of the QPack with the examples below (and more).
Method - Customizing Fonts for Parts of a Table
In the example below, I'm creating a custom table similar to our built-in [Autofit tables] using the CreateCustomTable function in R.
I'm specifying a different font type for each of the different parts of the table, e.g column, and row headers. To modify the below code for your own document, please read through the comments (denoted with #) and edit where appropriate. You can see other options for customizing fonts at CreateCustomTable.
- Right click in the Report tree and select Add R Output.
- Paste in the following R code in the R CODE box in the object inspector on the right:
#specify which table you want to format
mytable = table.Income.5
#create custom table
flipFormat::CreateCustomTable(mytable,
font.size=8,
col.header.font.size=15,
row.header.font.style="italic",
row.header.font.color="steelblue")
3. Right click on the R Output and select Calculation Options.
4. 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.
Method - Customizing Fonts Based on Data in a Table
In the example below, I'm creating a custom table similar to our built-in Autofit tables using the CreateCustomTable function in R. You may want to review the Matrix section of [INSERT LINK How to Work with Data in R] to help understand what the code is doing.
I'm specifying a different font for rows with a small sample size and for the row headers of rows with the highest values. To modify for your own document, please read through the comments (denoted with #) and edit where appropriate. You can see other options for customizing the font at CreateCustomTable.
- Right click in the Report tree and select Add R Output.
- Paste in the following R code in the R CODE box in the object inspector:
#specify which table you want to format
mytable = table.Income.5
###set the cell background colors
#make matrix of cell.colors the same shape as your table
#default the color to white
cell.font.colors=matrix("black",nrow=NROW(mytable),ncol=NCOL(mytable))
#shade cells with low counts
cell.font.colors[mytable[,2] < 20,2]="red"
###set the font sizes
#create matrix of default font sizes to 12
cell.font.sizes=matrix(12,nrow=NROW(mytable),ncol=NCOL(mytable))
#increase the font where the first column is over 15 to highlight
cell.font.sizes[mytable[1:NROW(mytable)-1,1] > 15,1]=15
###set the font weights
#create matrix of font weights default to unbolded
cell.font.weights=matrix("normal",nrow=NROW(mytable),ncol=NCOL(mytable))
#bold the data where it's over 15
cell.font.weights[mytable[1:NROW(mytable)-1,1] > 15,1]="bold"
###set the row header colors
#create list of colors defaulting to black
row.font.colors=rep("black",length(rownames(mytable)))
#where the data is over 15 change the row header to red
row.font.colors[mytable[1:NROW(mytable)-1,1] > 15]="red"
#create custom table
flipFormat::CreateCustomTable(mytable,
col.widths=c(40,30,30),
cell.font.color=cell.font.colors,
cell.font.size=cell.font.sizes,
cell.font.weight=cell.font.weights,
row.header.font.color=row.font.colors)
3. Right click on the R Output and select Calculation Options.
4. 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.
See Also
How to Customize a Table using CreateCustomTable in R
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
How to Add Statistical Significance to CreateCustomTable R Tables
How to Work with Conditional R Formulas