<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Deneb - Legend to show mean and median in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Deneb-Legend-to-show-mean-and-median/m-p/2818669#M5731</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/421796"&gt;@DW868990&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Hard to verify for sure without seeing your specification, but legends in Vega-Lite are designed to work in conjunction with encodings, and automate the manual creation of the marks to support them. If you're adding layers and marks to represent additional aspects of your data then these probably can't be automated into a legend.&lt;/P&gt;
&lt;P&gt;Your best bet would probably be to plot separate marks for each additional mark that you wish to have a 'legend' for, and specify their positions manually, so that they appear where you would like them to.&lt;/P&gt;
&lt;P&gt;The approach I might take to attempt this to do this would be to use an empty dataset in such a layer and manually position them.&lt;/P&gt;
&lt;P&gt;I'll do a simple example with the following specification:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  "data": {"name": "dataset"},
  "config": {
    "style": {
      "mean": {
        "stroke": "black",
        "strokeWidth": 2
      }
    }
  },
  "layer": [
    {"mark": {"type": "point"}},
    {
      "transform": [
        {
          "aggregate": [
            {
              "op": "mean",
              "field": "$ Sales",
              "as": "mean_sales"
            }
          ],
          "groupby": ["Product"]
        }
      ],
      "mark": {
        "type": "tick",
        "style": "mean"
      },
      "encoding": {
        "x": {"field": "mean_sales"}
      }
    }
  ],
  "encoding": {
    "x": {
      "field": "$ Sales",
      "type": "quantitative"
    },
    "y": {"field": "Product"}
  }
}&lt;/LI-CODE&gt;
&lt;P&gt;This produces a simple categorical scatterplot, with a black tick representing the mean, e.g.:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmp_0-1664939561761.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/798535i790ADB0CD43996A2/image-size/large?v=v2&amp;amp;px=999" role="button" title="dmp_0-1664939561761.png" alt="dmp_0-1664939561761.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note that I'm leveraging a style in my config, so that I can reuse the cosmetic aspects of the median mark.&lt;/P&gt;
&lt;P&gt;Now, I can add a dedicated layer and marks for the 'legend', e.g.:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  ...
  "layer": [
    ...
    {
      "description": "Mean 'legend'",
      "data": {"values": [{}]},
      "layer": [
        {
          "description": "The tick symbol",
          "mark": {
            "type": "tick",
            "style": "mean"
          }
        },
        {
          "description": "The 'legend' text",
          "mark": {
            "type": "text",
            "text": "median",
            "align": "left",
            "dx": 10
          }
        }
      ],
      "encoding": {
        "x": {
          "value": {
            "expr": "width - 50"
          }
        },
        "y": {"value": 0}
      }
    }
  ],
  ...
}&lt;/LI-CODE&gt;
&lt;P&gt;Here, I've added a nested layer with two marks: one to represent the median symbol (rule), and the other is a text mark with the text, 'median' in it. The rule mark also re-uses the style for the median indicator, so they have the same appearance.&lt;/P&gt;
&lt;P&gt;This layer uses a shared encoding with x and y values (not fields) that manually specify the position of the marks, and will override the higher-level ones. Vega-Lite will accommodate the rest of the chart around this, e.g.:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmp_1-1664940261775.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/798538i5631FE5AF681F65D/image-size/large?v=v2&amp;amp;px=999" role="button" title="dmp_1-1664940261775.png" alt="dmp_1-1664940261775.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;It would be a similar step to add the mean to the chart.&lt;/P&gt;
&lt;P&gt;If this still leaves you with questions, then if you're able to share your specification and some sample data (ideally in a workbook), I can take a look to see if I can provide more targeted assistance.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Oct 2022 03:28:14 GMT</pubDate>
    <dc:creator>dm-p</dc:creator>
    <dc:date>2022-10-05T03:28:14Z</dc:date>
    <item>
      <title>Deneb - Legend to show mean and median</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Deneb-Legend-to-show-mean-and-median/m-p/2815937#M5730</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Not sure if the below is possible but any advise would be appreciated -&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a custom deneb visual which is a categorical scatter plot, and a layer/mark for both median and mean.&lt;/P&gt;&lt;P&gt;One is a tick and one is a square.&lt;/P&gt;&lt;P&gt;Is s there a way in Deneb to show what the tick and square represents in the legend for the end user?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JJ&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 06:54:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Deneb-Legend-to-show-mean-and-median/m-p/2815937#M5730</guid>
      <dc:creator>DW868990</dc:creator>
      <dc:date>2022-10-04T06:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Deneb - Legend to show mean and median</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Deneb-Legend-to-show-mean-and-median/m-p/2818669#M5731</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/421796"&gt;@DW868990&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Hard to verify for sure without seeing your specification, but legends in Vega-Lite are designed to work in conjunction with encodings, and automate the manual creation of the marks to support them. If you're adding layers and marks to represent additional aspects of your data then these probably can't be automated into a legend.&lt;/P&gt;
&lt;P&gt;Your best bet would probably be to plot separate marks for each additional mark that you wish to have a 'legend' for, and specify their positions manually, so that they appear where you would like them to.&lt;/P&gt;
&lt;P&gt;The approach I might take to attempt this to do this would be to use an empty dataset in such a layer and manually position them.&lt;/P&gt;
&lt;P&gt;I'll do a simple example with the following specification:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  "data": {"name": "dataset"},
  "config": {
    "style": {
      "mean": {
        "stroke": "black",
        "strokeWidth": 2
      }
    }
  },
  "layer": [
    {"mark": {"type": "point"}},
    {
      "transform": [
        {
          "aggregate": [
            {
              "op": "mean",
              "field": "$ Sales",
              "as": "mean_sales"
            }
          ],
          "groupby": ["Product"]
        }
      ],
      "mark": {
        "type": "tick",
        "style": "mean"
      },
      "encoding": {
        "x": {"field": "mean_sales"}
      }
    }
  ],
  "encoding": {
    "x": {
      "field": "$ Sales",
      "type": "quantitative"
    },
    "y": {"field": "Product"}
  }
}&lt;/LI-CODE&gt;
&lt;P&gt;This produces a simple categorical scatterplot, with a black tick representing the mean, e.g.:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmp_0-1664939561761.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/798535i790ADB0CD43996A2/image-size/large?v=v2&amp;amp;px=999" role="button" title="dmp_0-1664939561761.png" alt="dmp_0-1664939561761.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note that I'm leveraging a style in my config, so that I can reuse the cosmetic aspects of the median mark.&lt;/P&gt;
&lt;P&gt;Now, I can add a dedicated layer and marks for the 'legend', e.g.:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  ...
  "layer": [
    ...
    {
      "description": "Mean 'legend'",
      "data": {"values": [{}]},
      "layer": [
        {
          "description": "The tick symbol",
          "mark": {
            "type": "tick",
            "style": "mean"
          }
        },
        {
          "description": "The 'legend' text",
          "mark": {
            "type": "text",
            "text": "median",
            "align": "left",
            "dx": 10
          }
        }
      ],
      "encoding": {
        "x": {
          "value": {
            "expr": "width - 50"
          }
        },
        "y": {"value": 0}
      }
    }
  ],
  ...
}&lt;/LI-CODE&gt;
&lt;P&gt;Here, I've added a nested layer with two marks: one to represent the median symbol (rule), and the other is a text mark with the text, 'median' in it. The rule mark also re-uses the style for the median indicator, so they have the same appearance.&lt;/P&gt;
&lt;P&gt;This layer uses a shared encoding with x and y values (not fields) that manually specify the position of the marks, and will override the higher-level ones. Vega-Lite will accommodate the rest of the chart around this, e.g.:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmp_1-1664940261775.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/798538i5631FE5AF681F65D/image-size/large?v=v2&amp;amp;px=999" role="button" title="dmp_1-1664940261775.png" alt="dmp_1-1664940261775.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;It would be a similar step to add the mean to the chart.&lt;/P&gt;
&lt;P&gt;If this still leaves you with questions, then if you're able to share your specification and some sample data (ideally in a workbook), I can take a look to see if I can provide more targeted assistance.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 03:28:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Deneb-Legend-to-show-mean-and-median/m-p/2818669#M5731</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2022-10-05T03:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Deneb - Legend to show mean and median</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Deneb-Legend-to-show-mean-and-median/m-p/2830794#M5867</link>
      <description>&lt;P&gt;Fantastic, this worked perfectly. The flexibility within Deneb is so good, thank you&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 11:23:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Deneb-Legend-to-show-mean-and-median/m-p/2830794#M5867</guid>
      <dc:creator>DW868990</dc:creator>
      <dc:date>2022-10-10T11:23:48Z</dc:date>
    </item>
  </channel>
</rss>

