cedar icon indicating copy to clipboard operation
cedar copied to clipboard

v1 error chart

Open tomwayson opened this issue 7 years ago • 3 comments

@rgdonohue asked in slack about how you can adapt the v0 error bars example to work in v1. Here's a working example:

Go to http://cedar-v1.surge.sh/ and enter the following in the JSON editor:

{
  "type": "bar",
  "datasets": [
    {
      "data": {
        "features": [
          {"attributes": {"state": "CA", "pop": 5000, "error": 2000}},
          {"attributes": {"state": "AZ", "pop": 2000, "error": 1400}},
          {"attributes": {"state": "NY", "pop": 8000, "error": 1000}}
        ]
      }
    }
  ],
  "series": [
    {
      "category": {"field": "state", "label": "State"},
      "value": {"field": "pop", "label": "Population"}
    }
  ],
  "overrides": {
    "valueAxes": [{
      "id": "v1"
    }],
    "graphs": [{
      "balloonText": "value:<b>[[value]]</b><br>error:<b>[[error]]</b>",
      "bullet": "yError",
      "bulletSize": 10,
      "errorField": "error",
      "bulletAxis": "v1"
    }]
  }
}

You will get something like this:

image

The key is the overrides section which allows you to set the relevant AmCharts properties to match their error char example.

@benstoltz

If we want to make this easier we should add default ids to the spec axes.

@ajturner @ghudgins

Do we want to open an issue for the Cedar JSON to support errors, perhaps by allowing users to specify an errorField on series, so that consumers don't have to use overrides?

tomwayson avatar Jun 21 '18 19:06 tomwayson

@tomwayson A need is often to do more than draw these bars for a single error value but to draw them according to upper and lower confidence interval values, which won't be symmetrical for non-normalized distributions.

rgdonohue avatar Jun 22 '18 19:06 rgdonohue

That makes sense. I did a quick check and did not see a way to do it in amCharts. If it can be done in amCharts, it can be done in cedar v1.

tomwayson avatar Jun 22 '18 21:06 tomwayson

There's a "bulletOffset" option for the graphs. Seems like we should be able to deduct the difference between the UCI and value from the LCI and value, and then offset the bullet with that number. Not currently working for me though.

rgdonohue avatar Jun 26 '18 23:06 rgdonohue