Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fold transform doesn't support #173

Open
Ying456123 opened this issue Aug 27, 2019 · 1 comment
Open

Fold transform doesn't support #173

Ying456123 opened this issue Aug 27, 2019 · 1 comment

Comments

@Ying456123
Copy link

Hi,
Sorry to ask as a new user. When I want to compare two columns with layers, I cannot encode color with two columns. Even if I add the encodeColor on the second layer, it doesn't behave as I expected.
Below is original code:

val data = Seq(
      ("te1", 300.0, 17.0),
      ("te2", 50.0, 19.0),
      ("te1", 40.2, 21.3),
      ("te2", 15.0, 21.5)
    )

val df = spark.createDataFrame(data).toDF("col", "data1", "data2")
Vegas.layered("Plots two layers").
  withDataFrame(df).
  withLayers(
    Layer().
      mark(Bar).
      encodeX("col", Ordinal, scale=Scale(bandSize=10)).
      encodeY("data1", Quantitative).
      encodeColor(field="data1", dataType=Quantitative),
    Layer().
      mark(Bar).
      encodeX("col", Ordinal, scale=Scale(bandSize=10)).
      encodeY("data2", Quantitative)
  ).
  show

image
After I add the encodeColor on second layer, it behaves as below:

Vegas.layered("Plots two layers").
  withDataFrame(df).
  withLayers(
    Layer().
      mark(Bar).
      encodeX("col", Ordinal, scale=Scale(bandSize=10)).
      encodeY("data1", Quantitative).
      encodeColor(field="data1", dataType=Quantitative),
    Layer().
      mark(Bar).
      encodeX("col", Ordinal, scale=Scale(bandSize=10)).
      encodeY("data2", Quantitative).
      encodeColor(field="data2", dataType=Quantitative)
  ).
  show

The result:
image
Could anyone help? Thanks a lot.

@Ying456123 Ying456123 changed the title How to encode color for two columns? Fold transform doesn't support Aug 28, 2019
@Ying456123
Copy link
Author

Now I found using fold transformation can give me the expected result, but seems like Vegas doesn't support it now.
Below is my Vega-lite's script and result:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "description": "A bar chart showing the US population distribution of age groups and gender in 2000.",
  "data": {
         "values": [
      {
        "col": "row1",
        "data1": 28,
        "data2":30
      },
      {
        "col": "row2",
        "data1": 47,
        "data2":105
      },
      {
        "col": "row3",
        "data1": 71,
        "data2":177
      }
    ]
     
     },
       "transform": [{"fold": ["data1", "data2"]}],
       "mark":"bar",
       "encoding":{
         "x":{"field":"col", "type":"nominal"},
          "y": {"field": "value", "type": "quantitative"},
         "color":{"field":"key","type":"nominal"}
       }
}

result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant