This article will take you through how to customize the legend in your visualization. It covers general settings, and will focus specifically on updating the labels and re-positioning the legend.
Requirements
- A non-legacy visualization which doesn't use small multiples and which points to a crosstab or a summary grid table that has both rows and columns.
- "Legacy" visualizations, on the other hand, will only appear as options when Show legacy visualizations is ticked at the bottom of the Visualization Selector menu when you click on a visualization type, and will typically have "with Tests" in their name. These charts do not include the same level of customization, and can only appear as a block or with arrows to individual legend items.
Method
Under Chart > Legend, there are various options to customize how the legend appears in your visualization.
1. By default, the Legend field is set to Automatic and will only show a legend if the visualization type and data format is appropriate, for example, when there are multiple series. This can be changed to Show or Hide when required.
2. You can manually set the font style, or select Use default or template fonts to use the formatting settings from the R visualization template selected in Chart > Appearance > Use template.
Editing legend names
The names that appear in the legend come from the column names of the underlying table. You can edit the name shown in the legend by either changing the names in the table or the visualization settings.
In this example, the table used to create the visualization is shown below, with columns labeled Male Female, and NET.
Note that by default NET, Total and SUM are ignored based on the Columns to ignore field under Data > Column Manipulations. Thus only the Male and Female data are plotted in the visualization. Note, if you select Data > Data Manipulation > Switch rows and columns, the series shown in the legend will actually be the Rows of the input table.
There are various ways you can update the legend labels:
- Rename the appropriate rows/columns in your table: This can be done by right clicking on the table directly > Rename. Or by renaming them in the Data Sources tree via renaming the Variable right-click > Rename or the Data > Properties > Labels depending on how your data is structured.
- If you don't want this renaming to flow through the rest of your report, you can just edit the names on the visualization individually via the Data > Column Manipulations > Column labels field. You will supply a list of names separated by a commas. Note, if you only enter a single label, it will replace only the first legend label.
Re-positioning the legend
The first step when positioning the legend is to set Legend orientation to either Vertical or Horizontal depending on whether you would like to have the labels going down or across.
By default, vertical legends go to the top right of the plot area whereas the horizontal legend will be centered below the bottom axis.
If you'd like to adjust the placement of the legend you can adjust the numbers using the Horizontal placement and Vertical placement fields. The numbers used for the placement are relative to the plot area and container area for the visualization. The plot area ranges from 0 to 1 and the edges of the visualization's container is -2 to 3. The diagram below shows the different areas described and their horizontal and vertical coordinates.
Note that with more extreme numbers, the plot area will resize to be smaller so most placement numbers used should be closer to 0 and 1. You can additionally check both Margins > Customize margins and Automatically expand margins, and then adjust the placement settings where necessary.
Specifically:
-
Horizontal placement is set using a value where -2 represents the far left and 3 represents the far right.
- 1 is to the right of the plot area in line with the last axis X point.
- 0.5 is half way across the plot area.
- 0 is level with the y-axis on the left part of the plot area.
- -0.5 is to the left of the y-axis/plot area.
- 1.02 is just to the right of the plot area.
-
Vertical placement is set using a value where -2 represents the very bottom and 3 represents the very top.
- 1 is level with the top of the plot area.
- 0.5 is half way down the plot area.
- 0 is level with the bottom of the chart above the x-axis.
- -0.2 is below the x-axis, usually below the axis labels.
- 1.02 is slightly above the top of the plot area.
To help position the legend, you can also adjust the width of the legend labels when Legend orientation is set to Vertical by wrapping the legend labels and setting a width in characters.