Skip to content

faceted geo plot text mark - weighted average #1428

Answered by mbostock
pdebruic asked this question in Q&A
Discussion options

You must be logged in to vote

Sounds like you want the groupZ transform; you probably don’t need a custom transform for this.

Assuming a data structure like this of weighted values:

data = [
  {value: 1, weight: 1, facet: "a"},
  {value: 2, weight: 3, facet: "a"},
  {value: 3, weight: 4, facet: "a"},
  {value: 4, weight: 8, facet: "a"},
  {value: 3, weight: 1, facet: "b"},
  {value: 5, weight: 9, facet: "b"},
  {value: 3, weight: 1, facet: "c"},
  {value: 2, weight: 2, facet: "c"},
  {value: 1, weight: 1, facet: "c"}
]

You can plot the (non-weighted) mean of observed values using the groupZ transform with the mean reducer like so:

Plot.plot({
  marks: [
    Plot.dot(data, {y: "weight", fx: "facet"}),
    Plot.tickY(data

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pdebruic
Comment options

Answer selected by pdebruic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants