September 29 2022

Agenda

  • Case studies:
    • Artists in the USA
    • Avocado data

Case Study 1: Artists in the USA

Data

We will be working with data on Artists in the USA.

More specifically, we will be building a visualization on aggregate data based on the original data set.

Discuss with a classmate(s) which variables you’d map to what elements in your plot. You can draft it out on paper (that’s often very helpful).

Starting out

  1. Download starter project
  2. Add your scales and axes
  3. Add marks
  4. Do any data transformations (sorting, filtering, etc.) that you deem necessary

Visualizing two categorical variables

For dealing with multiple categorical variables, we can add color to encode one of our variables.

We can use the stack transform to generate different y2/x2 values.

transform: [
  {
    type: "stack",
    groupby: ["type"],
    field: "percent",
    as: ["x0", "x1"],
    sort: { field: "race" }
  }

Update your spec

  1. Add a color scale (if you haven’t already) for the field race
  2. Use the newly created variables (x0 and x1) in your marks spec
  3. Sort the bars so we can make sense of the proportions (which variable should you sort by?)
  4. Add a legend and titles

Case Study 2: Avocado Prices

Data