This article describes how to create a CreateCustomTable R table (similar to a table with Autofit checked) to align sample sizes to bars on a visualization.
Requirements
Please note these steps require a Displayr license.
- A visualization
- A table that includes the same categories as the visualization and the values you'd like to show aligned to the visualization. In this example, the table has been sorted based on percentage and the Count statistic will be used for the sample size:
Method
1. Go to the Calculation icon > Custom Code in the toolbar.
2. Click onto the page to place the custom calculation.
3. Paste the below under General > R CODE:
#specify your table and the statistic you'd like to use
#if the statistic is not in its own column, replace [,"Count"] with [,,"Count"]
n = as.vector(table.Q3.Preferred.cola[,"Count"])
#add a prefix to each count
n = paste0("n=",n) # Add 'n=' to each value
# Create the custom table that can resize the data to align with the visualization
flipFormat::CreateCustomTable(n,
font.size=10,
transpose = T)
- The above code pulls in the Count values from our cola brand table without the row headers. To apply this in your own document, you should replace the table reference on the first line of the code.
- We then use the paste0 function to add the prefix of "n=" to each individual sample size.
- Finally, we use flipFormat's CreateCustomTable function to display the sample sizes in a smaller font and transpose them as a single row.
4. Re-position and re-size your custom table by dragging until it lines up with your visualization with the correct spacing.
Next
All customizations available are listed in CreateCustomTable
How to Select the Type of Table that is Right for You
How to Create a CreateCustomTable R Table of Images
How to Customize Colors on a CreateCustomTable R Table