Few questions after migrating from GDS

Hi all,

I’m on the journey of switching from Google Data Studio to Observable. So going through the learning curve reading all the guides and tutorials.

Now I’m running into a few basic things to which I can’t seem to find the right examples. Hopefully, someone will be able to point me in the right direction.

  1. Let’s say I want to display a chart that shows the distribution of people in a specific age group (0-10, 10-20, etc). My guess is that I would need to use the bin function for that. Is that correct? And if so, how can I specify the age brackets of the group. Or am I looking in completely the wrong direction?

  2. Another question related to grouping but slightly different. Let’s say I want to group my data into “male”, “female” and “other responses”. My guess here would be that to aggregate “other responses” I should use the transform function, is that correct?

  3. My next challenge is related to filtering. How can I create a filter to only show ages between 18-70 years? Or to exclude anything below 18?

  4. Finally I’m looking into continuous scales. Let’s say I’m plotting the number of records per age and I also want to include the ages on the X-axis that don’t have any records. How do I show those empty values on the X-axis?

Apologies if my questions aren’t completely clear but I’m happy to provide any additional info needed!

Thanks for the questions and for trying Plot. Here’s a notebook with a few examples:

Feel free to fork it and experiment more!

3 Likes

On the last point, here is a fork of Fil’s suggestion that demonstrates using a filter transform after binning and stacking. That way the scale domains are not affected by the filter operation.

Plot.plot({
  height: 250,
  marks: [
    Plot.rectY(
      population,
      Plot.filter(
        ([d]) => d.age >= ageMin && d.age <= ageMax,
        Plot.stackY(
          Plot.binX(
            { y: "count" },
            {
              x: "age",
              fill: (d) => (["R", "L"].includes(d.hand) ? d.hand : "other"),
              interval: 5
            }
          )
        )
      )
    ),
    Plot.ruleY([0])
  ],
  color: { legend: true }
}) 
2 Likes

Thanks a lot, @Fil @mbostock ! These examples are super helpful. I’m going to dive into them and try to replicate them on my dataset. Will report back!

2 Likes

@Fil Wow! You didn’t only help me to find the answers you also helped me to understand what is going on.

There’s one more thing I’m curious about. How would you create a continuous scale that also shows ages that don’t have a count? In your first chart for example.

I’ve added a new example in this cell. It uses thresholds: 90, but you could alternatively use interval: 1.

Got it! Needed to wrap my head around that it’s not using barY but rect/stackY.