This article describes how to apply rules to default tables and charts in Q (i.e. not R tables or R-based visualizations). Rules are a set of predefined automated functions – most commonly they could be thought of as a way of conditionally formatting tables (where you specify the conditions). But the range of available functions extends well beyond formatting. The current library of automated options includes (but is not limited to):
- Highlighting cells or chart series via custom criteria (e.g., ranges, greater/less than, top n).
- Applying color scales to entire tables or charts.
- Adding text, symbols to table cells or chart data labels.
- Customizing significance comparisons.
- Removing rows or columns or hiding cells based on specific criteria (e.g., minimum sample size).
- Reformatting columns (e.g., include sample size; re-label but leave source variable intact).
- Customizing footers.
- Automatically re-sorting charts or tables, by columns or rows of your choice.
- Weighting selected columns or rows.
See the Rule Online Library for more information about each available rule. You can also copy these rules and edit them to suit your needs.
Method - Apply Rules
- To apply a rule, simply select your table, go to Automate > Browse Online Library in the toolbar, and choose the appropriate rule. Rules can be identified by the highlighted table icon on the left of each menu item.
- The selected rule will then be added to the Rules tab.
- You are able to add multiple rules to your table. Note, the rules will be applied in the order they appear in this view. Depending on the rules being used, you may need to change the order via the Up and Down buttons to ensure they work as intended. For example, if you wish to highlight table cells but also want to remove values under a specific value, you would need to apply the highlighting cells rule first.
- To automatically apply this rule to all new tables, tick New items for this rule.
- To add this rule to all existing tables, right-click and select Apply > Add to every item in the project.
- To add this rule to all selected tables, right-click and select Apply > Add to selected items.
- Note that changing the dimensions of a table by, for example, using the Swap rows and columns option will affect the implementation of the rule. You may then need to apply an alternate rule if it is specific to rows or columns.
Alternative ways of applying rules
Highlight cells rules
By selecting Automate > Highlight Cells Rules you can create rules about how to color cells based on the range of values in the cells.
Top/Bottom rules
By selecting Automate > Top/Bottom Rules you can create rules about whether to select higher or lower-valued cells (e.g., top 10%, below average).
Color scale
By selecting Automate > Color Scale you can shade cells according to their values (i.e., creating heat maps).
Data bars
By selecting Automate > Color Scale you can create a Grid of Bars plot, such as in the example below.
Method - Manage Rules
- You can access the Rules in your project by clicking on any table in your Outputs tab and selecting the Rules tab. This tab will be highlighted pink when a rule is being applied.
- You can also access this directly from the toolbar via Automate > Manage Rules.
- In the Show drop-down, you can switch between Rules applied to selected items and All rules in project.
Method - Edit Rules
- To edit rules, right-click the appropriate rule in the Rules tab and select Edit Rule.
- OPTIONAL: Select Edit JavaScript > OK to customize the underlying code further.
- Change the necessary settings and press the Play button > Close > OK > OK.
Method - Create Rules
All the rules are written in JavaScript (see Table JavaScript and Plot JavaScript for details). You can write your own rules in JavaScript, applying them by selecting Automate > Custom Rule. See How to Create a Custom Rule and How to Customize a Rule for more information.
- To create custom rules, from the toolbar go to Automate > Custom Rule or from the Rules tab select New Rule.
- Enter your JavaScript code and press the Play button > Close > OK > OK.
Method - Delete Rules
-
To delete rules, right-click the appropriate rule in the Rules tab > Delete Rule. Note, if you have applied this rule to all tables in one step (as opposed to doing so individually) or have copied a table with the rule already applied, this option will delete it from all tables that use this rule.
- Alternatively, you can delete the rule from all existing tables by right-clicking and selecting Apply > Remove from every item in the project.
- To only remove the rule from selected tables, right-click and select Apply > Remove from selected items. This is the same as the toolbar option via Automate > Clear Rules > From Selected Tables or Charts.
- To only remove the rule from non-selected tables, right-click and select Apply > Remove from items that are not selected.