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.
A visualization connected to a table that includes a sample size statistic. In this example, the table has been sorted based on percentage and the Count statistic will be used for the sample size:
1. Go to Calculation > Custom Code in the toolbar.
2. Paste the below under Properties > R CODE:
n = as.vector(table.Q3.Preferred.cola[,"Count"]) # Get sample sizes
n = paste0("n=",n) # Add 'n=' to each value
# Create custom table
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.
3. Re-position and re-size your custom table by dragging until it lines up with your visualization with the correct spacing.