Change shapes in linked chart example

Hello @Greg ,
I really liked your Deneb Example - Linked Charts - Deneb Showcase - Enterprise DNA Forum

I was actually working on something similar where I have forecasts vs actuals plotted on the x/y axis with the possibility to select points giving details about each project on the right table.

Your example gave me the idea to plot the shape of the points based on a field (in my case actuals minus forecast sign) - I had not thought about this - and it looks great.
However, I would like to be able to specify which shape to use (in my case, triangle down for negatives, triangle up for positives). In the vega-lite documentation, it says that “shape” accepts an expression, but I was not able to make it work.
Taking your very nice example, how would you modify the “shape” code
“shape”: {
“field”: “Position”,
“type”: “nominal”,
}
in the “SYMBOL” layer to get the shape you want instead of the ones that are automatically attributed by Vega-Lite? (round and square)

(I am not attaching any files as your example is a perfect template for this question)
Thanks!
Kind regards
Valeria

Hi @valeriabreveglieri

My first thought was to move the shape block from the encoding block to the mark block. I then added a transform block with a simple calculation to generate a difference, then was able to use it in an expression in the shape key:expression pair in the mark block.

Here’s the code for the revised SYMBOL block:

            {
              "name": "SYMBOL",
              "transform": [
                {
                  "calculate": "70 - datum['Average Minutes']",
                  "as": "_variance"
                },
                {
                  "calculate": "if( datum['_variance'] < 0, -1, 1)",
                  "as": "_variance_sign"
                }
              ],
              "params": [
                {
                  "name": "_brush",
                  "select": "interval"
                }
              ],
              "mark": {
                "type": "point",
                "size": 200,
                "filled": true,
                "tooltip": true,
                "shape": {
                  "expr": "if( datum['_variance_sign'] == 1, 'triangle-up', 'triangle-down')"
                }
              },
              "encoding": {
                "color": {
                  "field": "Position",
                  "type": "nominal",
                  "legend": {
                    "orient": "bottom",
                    "symbolSize": 300,
                    "labelFontSize": 12,
                    "labelFontStyle": "italic"
                  }
                },
                "tooltip": [
                  {
                    "field": "Name",
                    "type": "nominal"
                  },
                  {
                    "field": "Team Full Name",
                    "type": "nominal",
                    "title": "Team"
                  },
                  {
                    "field": "Average Minutes",
                    "type": "quantitative",
                    "title": "Avg. Min."
                  },
                  {
                    "field": "Goals",
                    "type": "quantitative"
                  },
                  {
                    "field": "Shots",
                    "type": "quantitative"
                  },
                  {
                    "field": "Offsides",
                    "type": "quantitative"
                  },
                  {
                    "field": "Yellow Cards",
                    "type": "quantitative",
                    "title": "Yellows"
                  },
                  {
                    "field": "Assists",
                    "type": "quantitative"
                  }
                ]
              }
            },

Hope it helps.
Greg
eDNA Forum - Linked Charts - Symbol Shape by Difference.pbix (1.4 MB)

1 Like

@Greg Thanks!!! Works perfectly :slight_smile: I had not thought of moving the shape out of the encoding channel…
Have a good day!!!
Valeria