vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.66k stars 607 forks source link

Marginal histograms #3297

Closed domoritz closed 5 years ago

domoritz commented 6 years ago

Add a marginal histogram example. See https://www.tableau.com/about/blog/2015/11/how-make-scatterplot-marginal-histograms-45811.

domoritz commented 6 years ago
{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {"url": "data/movies.json"},
  "vconcat": [{
    "mark": "bar",
    "height": 100,
    "encoding": {
      "x": {
        "bin": true,
        "field": "IMDB_Rating",
        "type": "quantitative",
        "axis": null
      },
      "y": {
        "aggregate": "count",
        "type": "quantitative"
      }
    }
  }, {
    "hconcat": [{
      "mark": "rect",
      "encoding": {
        "x": {
          "bin": true,
          "field": "IMDB_Rating",
          "type": "quantitative"
        },
        "y": {
          "bin": true,
          "field": "Rotten_Tomatoes_Rating",
          "type": "quantitative"
        },
        "color": {
          "aggregate": "count",
          "type": "quantitative"
        }
      }
    }, {
      "mark": "bar",
      "width": 100,
      "encoding": {
        "y": {
          "bin": true,
          "field": "Rotten_Tomatoes_Rating",
          "type": "quantitative",
          "axis": null
        },
        "x": {
          "aggregate": "count",
          "type": "quantitative"
        }
      }
    }]
  }],
  "config": {
    "range": {
      "heatmap": {
        "scheme": "greenblue"
      }
    },
    "view": {
      "stroke": "transparent"
    }
  }
}
screen shot 2018-01-23 at 20 18 20
domoritz commented 6 years ago

This works pretty well. I wonder whether we should support customization of the layout in hconcat and vconcat so that we can remove the padding. hconcat could have a layout property or all layout properties could be top-level properties of the concat. Thoughts @kanitw?

kanitw commented 6 years ago

I think someone need to prototype the syntax for the underlying layout in Vega soon. There are also layout transforms that may make the term a bit overloaded.

Btw, I don't understand what's the issue here. Why don't you just add it? (What's the point of waiting? -- New people in the future will have to add their own new examples anyway.) A more interesting tasks is to modify your code to add box plot and dot plots to the margin instead.

g3o2 commented 6 years ago

I agree with @domoritz's suggestion that it would be useful to be able to get rid of the margins between the plots. Another use case is the so-called rug plot or dot-dash plot, in which ideally the marginal tick marks touch the domain of the main scatter plot.

Maybe allow the padding property for each unit spec of a composed spec ?

kanitw commented 5 years ago

We already have https://vega.github.io/vega-lite/examples/concat_marginal_histograms.html