October 6 2022

Agenda

  • Avocado prices
  • Baby names

Case Study: Avocado Prices

Data

Visualizing Raw Data

Let’s start with the raw data we have.

Create your scales and axes, mapping year to the x axis, and AveragePrice to the y axis.

For your marks, use symbol and just map x and y to their respective variables.

Data Transforms

We will use an aggregate transform to calculate the mean Average Price by year

transform: [
  {
    type: "aggregate",
    groupby: ["year"],
    fields: ["AveragePrice"],
    ops: ["mean"],
    as: ["m"]
  }
]

We can use view.data("name") in the JavaScript console

Change scales and marks

Your x scale is still year, but for y use the new mean variable you created in your data transform.

In addition to symbol, add a line transform with the same data.

What is the best choice for scale here, starting at zero or starting at the lowest mean price?

Case Study: Baby Names

The Data