This is the Code and result without color conditioning
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"width":806
data: {
url: {
%context%: true
index: index_ssd_2
body: {
size: 10000
_source: ["mediatype","pred_comp_sem"]
}
}
format: {property: "hits.hits"}
},
"transform": [
{"filter": "datum._source.mediatype == 'Valid Text'"},
{"filter": "datum._source.pred_comp_sem != 'Subject Line'"},
{
"joinaggregate": [{
"op": "count",
"field": "_source.pred_comp_sem",
"as": "a_count"
}],
"groupby": ["_source.pred_comp_sem"]
}]
"encoding": {
"y": {"field": "_source.pred_comp_sem", "type": "nominal", "sort": "-x", "title": null},
"x": {"field": "a_count","type": "quantitative", "title": null},
}
"layer":[{
"mark": "bar",
},
{
"mark": {
"type": "text",
"fontsize":40,
"align": "left",
"dx":5,
"aria": false
},
"encoding": {
"text": {"field": "a_count", "type": "quantitative"},
"color": {
"condition": {
"test": {"field": "a_count", "gt": 20},
"value": "white"
},
"value": "black"
}
}
}]
}
This the output
Below is the code with bar color conditioning
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"width":806
data: {
url: {
%context%: true
index: index_ssd_2
body: {
size: 10000
_source: ["mediatype","pred_comp_sem"]
}
}
format: {property: "hits.hits"}
},
"transform": [
{"filter": "datum._source.mediatype == 'Valid Text'"},
{"filter": "datum._source.pred_comp_sem != 'Subject Line'"},
{
"joinaggregate": [{
"op": "count",
"field": "_source.pred_comp_sem",
"as": "a_count"
}],
"groupby": ["_source.pred_comp_sem"]
}]
"encoding": {
"y": {"field": "_source.pred_comp_sem", "type": "nominal", "sort": "-x", "title": null},
"x": {"field": "a_count","type": "quantitative", "title": null},
}
"layer":[{
"mark": "bar",
"encoding": {
"color": {
"field": "a_count"
"type": "quantitative",
"legend": null,
}
}
},
{
"mark": {
"type": "text",
"fontsize":40,
"align": "left",
"dx":5,
"aria": false
},
"encoding": {
"text": {"field": "a_count", "type": "quantitative"},
"color": {
"condition": {
"test": {"field": "a_count", "gt": 20},
"value": "white"
},
"value": "black"
}
}
}]
}
This the output
I don't understand why bar length is differing in this case, the only thing I added is color encoding for bar.