So plot like Observable was created by the same person who created the library D3 if folks have heard of that or encountered that, seeing some nods. So Mike Bostock, who is also a CTO at Observable and some of our other teammates at Observable put together this awesome DataVis library that was released open source earlier this year.
And plot is a very high level library. So it allows you to really quickly get a meaningful chart up and running while at the same time giving you the flexibility to be able to customize and build exactly the right type of visualization that you need for your purposes as opposed to choosing one out of a limited set of options out of the box.
So how it does this is thanks to a very simple and yet very powerful API that is built on the notion of something called a grammar of graphics. So this is a way of thinking about describing and systematizing how we can put together a chart, pretty much any kind of chart we can imagine, from a few basic concepts.
And this is something that's been around in the data vis world for a long time, so we've got, like, experts and tons of decades of research in data vis kind of baked into this grammar of graphics. And then, PLOT itself employs this grammar of graphics, but implements it on top of D3. So we've also got Mike and the rest of the D3 teams, decade of experience building SVG-based visualizations for the web, all baked into this library.
So it's essentially like having a little data vis expert friend in your pocket that can just help you figure out the best chart to build. And so how it does that is by means of a few key concepts. We're not going to go in detail into all of them. You could read all about it. But there are things like marks, which are the visual elements we see on the page. This might be a bar. It might be a line. It might be dots in a scatter plot. There are scales, which are essentially functions that transform the values that I have in my data set, so in my data space, into values in the actual visual representation.
So this might be taking those frequency numbers and turning them into pixels of how high the bar is going to be on the screen. A couple of features we're not going to talk too much about, but are super useful for creating more custom visualizations, things like transforms, so we can do aggregations, like sum, mean, that sort of thing, and facets, which allow you to take a data vis and split it up into smaller subvisualizations that each focus on a subset of the data.
So with these just few concepts, which don't take too long to wrap your head around, you can actually create really powerful and really complex graphs that totally fit whatever your needs are. But at the same time, you can allow the defaults built into Plot to kind of make a lot of the decisions for you, so that you don't need to learn everything there is to know about how to perfectly lay out things on the screen.
So let's take a look at what it actually feels like to write some Plot. Hopefully, folks can read this okay in the back. I'm going to take that as a yes. Okay. So what I've got here is some data about these letters and their relative frequency. So I've got an array of little data objects, datums, that have a letter and a frequency property. To create a Plot, it is a simple call to the Plot method on this sort of capital P Plot object, which is going to create an SVG. And this SVG is super boring.
Comments