Vega: How to specify exact colors when using color scales for groupings?

Created on 9 Feb 2016  路  3Comments  路  Source: vega/vega

I am using a grouped line chart whereas which uses category10 range in color scale. Is there any way to specify exact color for each record?

This is very useful if we plot some scenarios such as election results where we should represent exact political party color in chart as well.

https://gist.github.com/keizer619/4f7212d3f9089f6c7e34

Most helpful comment

In the definition of your color scale, you can directly use an array of colors for its range:

{
  "name": "color",
  "type": "ordinal",
  "domain": {"data": "table","field": "EngineType"},
  "range": ["pink", "green"]
}

Now if you want to specifically bind each value to specific colors you can also hardcode the domain of this scale:

  "domain": ["Piston", "Rotary"],
  "range": ["pink", "green"]

All 3 comments

In the definition of your color scale, you can directly use an array of colors for its range:

{
  "name": "color",
  "type": "ordinal",
  "domain": {"data": "table","field": "EngineType"},
  "range": ["pink", "green"]
}

Now if you want to specifically bind each value to specific colors you can also hardcode the domain of this scale:

  "domain": ["Piston", "Rotary"],
  "range": ["pink", "green"]

It works and thank you very much for immediate response. I will close this issue.

how to assign different colour for circles representing different parameters in a matrix plot. I have almost six (6) parameters.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arvind picture arvind  路  5Comments

chadbr picture chadbr  路  6Comments

Fil picture Fil  路  5Comments

jheer picture jheer  路  5Comments

rubjo picture rubjo  路  4Comments