There are several ways you can customize the labels on your visualizations. This is done through the Chart > Data Labels > Annotation menu in the object inspector and is useful in several scenarios:
Changing significance arrows, carets or triangles to Bar, Column, Line, and Radar visualizations
Using letters for statistical testing
Circles, circles with borders, and shadows
Creating custom statistics for annotations
This article describes how to go from a visualization that does not display annotations or significance testing:
To a visualization that displays annotations and significance testing:
Requirements
- A Displayr document with at least one table.
- Knowledge of how to create visualizations (See: Creating and Modifying Visualizations)
- Familiarity with the types of significance testing in Displayr (See: How to Apply Significance Testing in Displayr)
Methods
Changing significance arrows, carets or triangles on Bar, Column, Line, and Radar visualizations
- Create a bar, column, line, or radar visualization by selecting an existing table (that doesn't show Column Comparison stat testing) and from the object inspector, click Visualization and select the appropriate visualization.
- With the visualization selected, go to Appearance > Significance and select Advanced from the pull-down menu. By default, Displayr's visualizations have Arrows and Font colors enabled. Use this menu to modify what types of significance tests are run.
- Select the Exception Tests tab and use the Significance Symbol menu to select the symbol you want to use to indicate significance. In this example, we will choose a Triangle.
- Click Apply to Selection.
- OPTIONAL: Use Chart > Appearance > Significance arrow size to adjust the size of the significance arrow (triangle) as necessary.
- OPTIONAL: Use Significance > Advanced > Significance Levels to change the color of the significance symbol as needed.
Using letters for statistical testing
There are two ways of showing column comparison letters on a visualization. One is by using legacy "with Tests" visualizations, but the available features and the way that it is formatted may not meet everyone's needs. If you'd rather use an R-based visualization that include more features and customizations, you can add the letters using an annotation to the data labels.
Method 1 - Using "with Tests" visualization:
- Select your table and click Appearance > Significance > Advanced.
- On the Significance Levels tab, go to the Show significance menu, and select Compare columns.
- Click Apply to Selection.
- Go to Anything
> Visualization > Visualization type > Visualization type with Tests.
- A new object will appear on the page. With it selected, from the object inspector, select your input table from the Data > Data Source > Data dropdown or click into the field and then click on the table name that appears on the table (in blue).
- Click on the Appearance tab in the object inspector, and update Significance to Compare columns.
- OPTIONAL: Click Chart in the object inspector to adjust the formatting as necessary.
In this example, I'm using Column > Column with Tests.
Method 2 - Using annotations on the visualization:
- Select your table and click Appearance > Significance > Advanced.
- On the Significance Levels tab, update the Show significance menu to Compare columns.
- Click Apply to Selection.
- Create a visualization from toolbar > Visualization
, such as Column > Column.
- Click onto the page to create the visualization.
- Tick the Chart > Data Labels > Show data labels box in the object inspector.
- Update Data Labels > Annotation(1) to Text - after data label.
- Enter "Column Comparisons" in Data (cell statistic) (1).
- Leave Threshold (1) blank.
- [OPTIONAL] Turn off arrows and font color results by going to Appearance > Significance and updating to No. Column comparisons will remain on the visualization.
- [OPTIONAL] Further customize the formatting of the stat testing annotation.
Circles, circles with borders, and shadows
In addition to arrows, carets, and text, it is possible to add a border around the data labels, which appears as a filled circle, empty circle with border, or shadow. These are selected as follows:
- Tick Chart > Data Labels > Show data values.
- Go to DATA LABELS > Annotation(1) and select the desired annotation type.
There are formatting options for controlling their size, colors, and line thicknesses.
In the example below, I've used the Circle - thick outline annotation type and adjusted the Size (1) setting:
Hiding labels
By setting Annotation (1) to Hide, rules can be used to hide annotations. For example, in the chart below, all labels below the threshold of 50% have been hidden. Note that this also hides the data label. You can think of "annotation" as a verb, so I am hiding any values and labels that are above the threshold of 50%.
Creating custom statistics for annotations
All the examples so far have used existing tables and their statistics to create the annotations. However, you can create your own custom statistic to annotate your visualization using R code. You'll take your table, create a new table within R with the custom statistic/calculations, and combine the two together, see How to Add a Custom Calculation and How to Combine Tables with Multiple Statistics Using R. You'll then reference that new calculation in the Annotation menu to apply your annotations.
You can also modify a statistic that's already in your table. In this example, the following code modifies a table called table.Preferred.cola.2.by.Age.6, by making all the column comparisons appear as uppercase. This modified table is then used as the input to the visualization.
x = table.Preferred.cola.2.by.Age.6
x[,,"Column Comparisons"] = toupper(x[,,"Column Comparisons"])
table.with.upper.case.stats = x
This last example creates a table, with a completely new statistic, called Comment and passes this through to the bar chart, with two annotations. Annotation (1) is set to Hide (to hide the labels) and Annotation (2) to Text - after label with Data (cell statistic) (2) set to Comment.
Looking at the R code used to create the table with the comment, key features are:
- A 3-dimensional array is created named "out" (this is the required structure of a table for use with annotation). Note that this three-dimensional array is a table, where there are multiple results in each cell of the table. In this case, the table has 12 rows and 1 column, where nrow(x) is the 12 rows of the table named table.Interview.Date (shown on the left). The first result in the cells of the table is % and the second is Comment.
- The Comment has been set to blank, except for July 2019, which has been set as New\ncampaign, where \n is the code for a new line.