Forum Discussion
Wind Direction Aster Plot
Hmm. Can't seem to get it to turn the right way, even with the theta adjustments. Also tried to add placeholders for the missing directions.
{
"data": {"name": "dataset"},
"layer": [
{
"mark": {
"type": "arc",
"innerRadius": 20,
"stroke": "#444"
}
},
{
"mark": {
"type": "text",
"radiusOffset": 50
},
"encoding": {
"text": {
"field": "Direction",
"type": "nominal"
}
}
}
],
"encoding": {
"theta": {
"field": "Theta",
"type": "quantitative",
"stack": false
},
"theta2": {
"field": "Theta2",
"type": "quantitative",
"stack": false
},
"radius": {
"field": "Sum of Count",
"scale": {
"type": "sqrt",
"zero": true
}
},
"color": {
"field": "Direction",
"type": "nominal",
"legend": true
}
}
}
Hi lbendlin,
If you want to explicitly bind the theta (and theta2) values to the radian representation from the data, you will need to use the value definition in the encoding (which maps the explicit value). If you bind a field, Vega-Lite will work out the angle based on the range of values from minimum to maximum (although you could probably manually set the range and domain on the scale to match the radian value, if you specifically wanted to still use the field definition).
Not sure if this is exactly what you're after but may get you closer:
{
"data": {"name": "dataset"},
"layer": [
{
"mark": {
"type": "arc",
"innerRadius": 20,
"stroke": "#444"
}
},
{
"mark": {
"type": "text",
"radiusOffset": 50
},
"encoding": {
"text": {
"field": "Direction",
"type": "nominal"
}
}
}
],
"encoding": {
"theta": {
"value": {"expr": "datum['Theta']"},
"type": "quantitative",
"stack": false
},
"theta2": {
"value": {"expr": "datum['Theta2']"},
"type": "quantitative"
},
"radius": {
"field": "Sum of Count",
"scale": {
"type": "sqrt",
"zero": true
}
},
"color": {
"field": "Direction",
"type": "nominal"
}
}
}
Cheers,
Daniel
- dm-p3 years agoSuper User
Updated version with a ThetaMid column (which is just the angle value in radians for the text mark):
{ "data": {"name": "dataset"}, "layer": [ { "mark": { "type": "arc", "innerRadius": 20, "stroke": "#444" } }, { "mark": { "type": "text", "radiusOffset": 50 }, "encoding": { "text": { "field": "Direction", "type": "nominal" }, "theta": { "value": { "expr": "datum['ThetaMid']" } } } } ], "encoding": { "theta": { "value": { "expr": "datum['Theta']" }, "type": "quantitative", "stack": false }, "theta2": { "value": { "expr": "datum['Theta2']" }, "type": "quantitative" }, "radius": { "field": "Sum of Count", "scale": { "type": "sqrt", "zero": true } }, "color": { "field": "Direction", "type": "nominal" } } }Cheers,
Daniel
- lbendlin3 years agoSuper User
Thank you for the insights. Need to bottle this up somehow. You're not planning to write a book or something on the finer details of data binding by any chance?
- ToriSugden2 years agoRegular Visitor
Hi Daniel,
I have been trying to extend this. I would like to colour code by wind speed (which then gives me labels for each one) and have the directions equidistant from the centre. I have created two charts one on top of the other. But wonder if there is a way to do it in one visual. I would also like the colours to be in wind speed order