Simple Histogram of Category Counts

I’m trying to create a chart of counts of categories. It’s very simple and, though an Observable newbie, I’ve done this before several times. But I can’t do it this time.

I don’t understand why the histogram only shows the total of all data items rather than breaking it out into categories.

I have several other working instances of this. I can reproduce this particular erroneous behavior in a working instance by misspelling the column to be grouped. But that doesn’t seem to be the case here.

1 Like

The problem is that "dest" is not a key for the objects in your data, rather " dest" (with a space at the beginning) is a key. Thus, you might try:

Plot.plot({
  marks: [
    Plot.barX(data, Plot.groupY({x: "count"}, {y: " dest"}))
  ]
})

Alternatively, you might edit the first line of your data file from this:

timestamp, dest

to remove the space:

timestamp,dest

I’m not sure if there’s a simple option to trim the white space in the keys or not.

Ugh. I checked for spaces at the end, but not the beginning. Thanks for the help. I removed the misleading space at the beginning.

1 Like