Hi @valeriabreveglieri,
@DaveC is correct in the approach, and it’ll be similar for Vega-Lite.
Scales and axes don’t look at the dataset on a row by rows basis, so calculating the maximum value as a transform
will not be something that domainMax
can obtain. It will ideally need to be a signal (param in Vega-Lite).
The strategy I would take is to get the extents (min/max) of the column values, find the max and multiply this by an appropriate amount.
We can debug as follows (note that this won’t work until you remove the erroring domainMax
from your spec lower down):
Step 1: Add basic param with pluck
of desired field
pluck
function doc
{
...
"params": [
...
{"name": "_max_scale_y", "expr": "pluck(data('dataset'), '# Count of Launches')"}
],
...
}
This gives us all unique values for that field:
Step 2: Add an extent
function
extent
function doc
{
...
"params": [
...
{"name": "_max_scale_y", "expr": "extent(pluck(data('dataset'), '# Count of Launches'))"}
],
...
}
The extent
function will give a 2-element array of min/max values from this field:
Step 3: Get the max value and multiply
{
...
"params": [
...
{"name": "_max_scale_y", "expr": "extent(pluck(data('dataset'), '# Count of Launches'))[1] * 1.1"}
],
...
}
We just use an array accessor to get the second entry (as this is 0-based, we use 1
for this). We will then have a number and we can multiply this as needed.
Step 4: Check/restore domainMax
Ensure that this uses your param/signal, e.g.:
{
...
"scale": {
"domainMax": {
"expr": "_max_scale_y"
}
},
...
}
Running your spec will now work as defined, e.g.:
You could probably use a better method to scale the max value, but hopefully this will give you ideas to proceed.
Workbook with revised spec attached. Good luck!
DM-P
Reporting Training Support Usage App - eDNA question [DM-P modified].pbix (2.9 MB)