Jump to content
  • How to label selected data points on a map or scatterplot

    This article provides tips for how to label only a selection of markers on a plot - when you have many markers.


    Using labels for markers on a map or scatter plot may provide useful information and clarity, but when there are many markers on the plot, labeling all markers may not be desirable.

    Luckily, Spotfire provides a way of selecting which markers to display in maps and scatterplots based on a custom expression on the Label axis.

    In the attached DXP file you can see three different ways of labeling the markers:

    • Label only selected stores
    • Label the top 10 selling stores (taking filtering into account)
    • Label selected stores through tags (iterate your way to a good set of labels by tagging those markers)

    In all three cases, the technique used is to use a custom expression with an IF or CASE statement on the label, that sets the label content to whatever is desired if the logical condition is true, and sets the label content to NULL if the condition is false. Labels that have the value NULL are not shown by Spotfire by default (check that the "show empty labels" checkbox is unchecked).

    Label selected stores only

    To select specific stores to label the following expression works.

    CASE    when [Store Name]="Marlon Gary" then [Store Name]
            when [Store Name]="Myrna Newman" THEN [Store Name]
            when [Store Name]="Mike Irons" THEN [Store Name]
            when [Store Name]="Wim Fellini" THEN [Store Name]
    Just add a line with "when [store name] = "XYZ" THEN [store Name] if you want to add more labels.

    Label top 10 stores

    To label the top 10 selling stores in the current filtering the following expression works:

     If(Rank([Class Sales],"desc")<11,[store Name],NULL)
    You can change the logic of the IF/CASE condition to reflect the labels you want to see on the map. The file I used is attached to this article in case you want to try it out.

    Label selected stores through tags

    Select View > Tags to show the tags panel. Tag collections can be added to a data table, and are essentially a new column where each row is untagged by default. You can add tags to your collection, and then attach them to select rows, by marking data rows in the visualization, and then drag & dropping the tag to attach it. Check out the online help for details on how to work with the Tags panel.

    To show labels only for tagged rows the following expression works: 

     If([Markers to label]!="",[City],NULL) 
    "Markers to label" = the name of my tag collection, and ?City? = the column that I want to use for labels.

    Instead of just having a single tag for when to show labels, you can include several tags in your collection, and fetch the labels from different columns for each as in this expression: 

       when [Choice of labels]="Type" then [Store Type]
       when [Choice of labels]="Store" then [Store Name]
    "Choice of labels" = the name of my tag collection that contains the two tags "Type" and "Store", and "Store Type" and "Store Name are the two columns that I want to use for labels respectively. 

    Just add another line for each new tag you add to your collection to specify which column to use for labelling those data rows. 

    The second page in the attached analysis file shows the Tags panel with these example tag collections and a scatter plot for each. You don't need to keep the Tags panel open once you are done iterating which data points to tag, and thus label. 

    Hope you find this useful and please don't hesitate to ask questions by using the 'ask a question' option on the community, please include the URL of this article in your question.



    User Feedback

    Recommended Comments

    There are no comments to display.

  • Create New...