Jump to content
We've recently updated our Privacy Statement, available here. ×
  • Configuring a Scatter Plot as a Beeswarm Plot


    Introduction to Beeswarm Plot

    Addendum - January 2024 - Please also consider using the Violin Plot Mod for Spotfire!

    Beeswarm plots are great to show both the overall distribution of a variable and the individual data points. They look like one-dimensional scatter plots displaying individual measures as points with the difference that a logic is applied to ensure that plotted points are closely packed and do not overlap. They are useful to display an information-dense summary of how the top features in a dataset impacts the model's output, showing the distribution of a single numeric metric across one or more categories.

    For people interest in learning more about dot plots/beeswarm plots and models for distributing the points on the chart then this article by LeLand Wilkson should prove useful: http://moderngraphics11.pbworks.com/f/wilkinson_1999.DotPlots.pdf

    Learn more about visualizations and dashboards with Spotfire®

    Creating a Beeswarm Plot in Spotfire®

    This configuration work with all versions of Spotfire. Creating a beeswarm plot relies on the generous configuration flexibility of the native Scatter Plot in Spotfire which also provided the foundation for chromosome maps, gantt charts, swim lanes, ternary plots and many others in the past. The challenge with configuring a beeswarm plot is the distribution of the points both into horizontal bands and distributing the points evenly within the bands.

    This tutorial uses a fictional data with measurements variables for 3 different categories of data. Download this dataset at the end of the page and open it in Spotfire.

    Open the visualizations panel and add a Scatter Plot to the canvas.

    screen_shot_2021-06-21_at_11_47_47.thumb.png.172d44c68183c836564ed51de03cfebc.png

    Select a category columns in the X-axis and select the quantitative metric of interest on the Y-axis. In this example we use the (Group) column as X-axis and (Metric) as Y-axis.

    screen_shot_2021-06-21_at_11_48_20.thumb.png.be8df613d55c6f5f1a1c74173440e794.png

    We want to allow the number of horizontal bands to be easily adjusted using a slider control. Create a Text area and add a Property Control of type Slider. In the Slider setting, click New and add a new Document Property named "Bins" of type Integer with a default value of 40. Then set property value through a "Numerical Range" between 10 to 100 by interval of 10 and click OK.

    screen_shot_2021-06-21_at_11_50_27.thumb.png.752f7f19b226ae378525332563136bfc.png

    Now we will use a calculated column to create the beeswarm horizontal bins based on the slider selection. Go to Data > Add calculated column? and paste-in this function: 

    BinByEvenIntervals([Metric],${Bins})

    We will name this new column ?Binned Metric?.

    screen_shot_2021-06-21_at_11_51_09.thumb.png.7f1b5ca32a81e7d77eeed1260738521b.png

    Back in the scatter plot, change the Y-axis to (Binned Metric). Now changing the binning value with the slider will change it in the scatter plot.

    screen_shot_2021-06-21_at_11_52_01.thumb.png.eb630e72e7589ddc91e5742d8903b2fc.png

    Next we need to evenly distribute the points within each horizontal band. To achieve this we will use another calculated column. Go back to Data > Add calculated column? and paste-in this function:

    Rank([Metric],"asc",[binned Metric],"ties.method=first") - (Max(Rank([Metric],"asc",[binned Metric],"ties.method=first")) over ([binned Metric]) / 2)

    We will name this new column ?Distributed Metric?.

    screen_shot_2021-06-21_at_11_52_40.thumb.png.000bf47d0689f00786529f0716e0ebac.png

    Back in the scatter plot, change the X-axis to (Distributed Metric) and also remove the Color-by configuration. Now the scatter plot is configured as a beeswarm plot and you can show more or less bins using the slider.

    screen_shot_2021-06-21_at_11_55_03.thumb.png.ce419a3e47f25c3735308fb092107fe6.png

    The (Distributed Metric) calculated column ranks our metric and then subtracted half the max rank (or record count) for that bin to distribute the records around a central axis. Using that method, within each horizontal band the values for the metric increases from left to right.

    Additional Configurations

    Trellising a beeswarm plot

    We want to compare the distribution for the 3 different groups that we have in our dataset using a trellis. 

    We will use a new calculated column t to combine the group category and the (Binned Metric) column. Go to Data > Add calculated column? and paste-in this function: 

    Concatenate([binned Metric], [Group])

    We will name this new column "Binned Metric Group"

    screen_shot_2021-06-21_at_12_11_22.thumb.png.530f3593ee4086af7a6a721160dced6d.png

    Next we need, again, to evenly distribute the points within each horizontal band. To achieve this we will use another calculated column. Go back to Data > Add calculated column and paste-in this function:

    Rank([Metric],"asc",[binned Metric Group],"ties.method=first") - (Max(Rank([Metric],"asc",[binned Metric Group],"ties.method=first")) over ([binned Metric Group]) / 2)

    We will name this new column "Distributed Metric Group".

    screen_shot_2021-06-21_at_12_19_35.thumb.png.29921bd01df43769fe99f8ce851dcc5d.png

    Back in the scatter plot, change the X-axis column to (Distributed Metric Group) and go to Properties > Trellis to use the (Group) column to trellis by.

    screen_shot_2021-06-21_at_12_22_22.thumb.png.f980c435c913318a1e961ef4e700fb06.png

    Drawing results as a bar chart

    We want to compare the distribution as bars. Right-click the beeswarm plot and  switch visualization to a Bar Chart. Then right click the visualization to change it to Horizontal Bars and use (Binned Metric) column as X-axis and (Distributed Metric Group) column as Y-axis using the Sum aggregation.

    screen_shot_2021-06-21_at_12_40_22.thumb.png.2f24c15318e4bc46d2dbf6b4ec24f400.png

    Now we need to change the Color-by expression. Click on the Color-by selector and paste-in the following expression:

    If([Distributed Metric Group]<=0,"left","right")

    And now use the same color for both left and right.

    screen_shot_2021-06-21_at_12_42_35.thumb.png.f17b49d9d37594fc775dd441c24f98b4.png

    Adding lines to the beeswarm plot

    Switching the Y-axis to the raw (Metric) column will allow to have lines for mean, q1, q3, etc. with the side effect of showing the rising Metric from left to right within each band, remember each band is still defined because the X-axis axis is still using a calculated column which takes into account the (Binned Metric) column.

    screen_shot_2021-06-21_at_12_52_52.thumb.png.c24ba2f099ffcbe0782d7326bd901329.png

    Drawing results as a dot plot

    A similar approach can be used to draw the results in a bar chart or to produce a dot plot, which is like a histogram but records are represented as individual points rendered and grouped into bins (bars).

    To do that, we need to create a new calculated column. Go back to Data > Add calculated column and paste-in this function:

    Rank([binned Metric],"asc",Concatenate([binned Metric],[Group]),"ties.method=first")

    We will name this new column ?Distributed Metric Oneside?.

    screen_shot_2021-06-21_at_12_57_19.thumb.png.0281eb2796d1ada4c2d50ef71b7a7468.png

    Open the visualization panel and add a Scatter Plot to the canvas. Select the (Binned Metric) column as X-axis and (Distributed Metric Oneside) on the Y-axis.

    screen_shot_2021-06-21_at_13_01_54.thumb.png.bd08b2ca8b42a5ec19d229e548cc8dfe.png

    Now change the trellis configuration to trellis by Rows and select the (Group) column.

    screen_shot_2021-06-21_at_13_03_02.thumb.png.a99860a867eb9c807f1acfdb523263d3.png

    You can also switch this visualization to a bar chart. Just right-click the visualization and select Bar Chart.

    screen_shot_2021-06-21_at_13_04_20.thumb.png.eff304b446cc4f118a5791d52b732fcc.png

    example_beeswarm.dxp

    example_data.csv_.zip


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...