# Waffle

> Show shares of a whole as a grid of unit squares the reader can count, then highlight one category, resize the grid and bucket small categories into Other.

A waffle chart draws the whole as a grid of squares, one square per unit, and fills them by category. It reads directly: 16 of 100 squares is 16%. It suits a few shares when the audience should be able to count them.

Use a [pie or donut](/docs/part-to-whole/pie-donut/) when exact counts do not matter and you want direct slice labels. Use a [bar chart](/docs/comparison/bar/) when there are many categories or the values are not shares of a total.

## A basic waffle

Set `mark` to `"waffle"`, put the share on `theta` and the category on `color`. The grid is 10 by 10 by default. Values normalize to the grid by largest-remainder rounding, so the squares always sum exactly even when the shares are fractional.

```json
{
  "mark": "waffle",
  "data": [
    {
      "source": "Coal",
      "share": 35.2
    },
    {
      "source": "Natural Gas",
      "share": 22.5
    },
    {
      "source": "Hydro",
      "share": 14.8
    },
    {
      "source": "Nuclear",
      "share": 9.2
    },
    {
      "source": "Renewables",
      "share": 15.6
    },
    {
      "source": "Oil & Other",
      "share": 2.7
    }
  ],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Coal still generates about a third of the world's electricity",
    "subtitle": "Share of global electricity generation, 2023. Each square is one percent; shares round to whole cells."
  }
}
```

## Highlighting a category

`highlight` on the `color` channel takes a category name, keeps that category in color and mutes the rest. Use it when one share is the point and the others are context.

```json
{
  "mark": "waffle",
  "data": [
    {
      "source": "Coal",
      "share": 35.2
    },
    {
      "source": "Natural Gas",
      "share": 22.5
    },
    {
      "source": "Hydro",
      "share": 14.8
    },
    {
      "source": "Nuclear",
      "share": 9.2
    },
    {
      "source": "Renewables",
      "share": 15.6
    },
    {
      "source": "Oil & Other",
      "share": 2.7
    }
  ],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "source",
      "type": "nominal",
      "highlight": "Renewables"
    }
  },
  "chrome": {
    "title": "Renewables generated about 16 of every 100 kilowatt-hours",
    "subtitle": "Share of global electricity generation, 2023. Each square is one percent."
  }
}
```

## Grid size

`units` sets the total number of squares and `columns` sets how many sit in each row, with rows derived as `units / columns`. These are mark options, so the mark becomes an object. Here 50 units in 10 columns make a 5 by 10 grid where each square is two percent.

```json
{
  "mark": {
    "type": "waffle",
    "units": 50,
    "columns": 10
  },
  "data": [
    {
      "category": "Healthcare",
      "spending": 24
    },
    {
      "category": "Social Security",
      "spending": 21
    },
    {
      "category": "Defense",
      "spending": 13
    },
    {
      "category": "Net Interest",
      "spending": 13
    },
    {
      "category": "All Other",
      "spending": 29
    }
  ],
  "encoding": {
    "theta": {
      "field": "spending",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Fifty cells make each square two percent",
    "subtitle": "Share of federal spending by category, fiscal year 2024"
  }
}
```

## Bucketing small categories

`other` on the mark folds categories below a share threshold into one trailing category. `other: 0.05` folds everything under 5%, and the object form `{ threshold, label }` renames the bucket. It is off by default, because bucketing is an editorial decision.

```json
{
  "mark": {
    "type": "waffle",
    "other": {
      "threshold": 0.05,
      "label": "Other emitters"
    }
  },
  "data": [
    {
      "country": "China",
      "emissions": 12600
    },
    {
      "country": "United States",
      "emissions": 4500
    },
    {
      "country": "India",
      "emissions": 3000
    },
    {
      "country": "Russia",
      "emissions": 1900
    },
    {
      "country": "Japan",
      "emissions": 1000
    },
    {
      "country": "Germany",
      "emissions": 620
    },
    {
      "country": "South Korea",
      "emissions": 590
    },
    {
      "country": "Iran",
      "emissions": 580
    },
    {
      "country": "Canada",
      "emissions": 530
    },
    {
      "country": "Indonesia",
      "emissions": 490
    },
    {
      "country": "Saudi Arabia",
      "emissions": 480
    },
    {
      "country": "Turkey",
      "emissions": 420
    }
  ],
  "encoding": {
    "theta": {
      "field": "emissions",
      "type": "quantitative"
    },
    "color": {
      "field": "country",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Countries under 5% fold into one category",
    "subtitle": "Annual CO₂ emissions among the top twelve emitters, 2024"
  }
}
```

## Fields that matter

| Field | What it does |
| --- | --- |
| `mark` | `"waffle"`, or an object that sets `units`, `columns` and `other`. |
| `mark.units` | Total number of squares. Default 100. |
| `mark.columns` | Squares per row. Default 10. |
| `mark.other` | A threshold as a fraction, or `{ threshold, label }`, that folds small categories into one. |
| `encoding.theta` | The quantitative share of each category. |
| `encoding.color` | The category. `highlight` singles one out. |

## Related

- [Pie and donut](/docs/part-to-whole/pie-donut/) for shares with direct slice labels.
- [Parliament](/docs/part-to-whole/parliament/) for countable seats in a hemicycle.
- [Stacked 100%](/docs/part-to-whole/stacked-100/) for shares across several wholes.
- [Bar](/docs/comparison/bar/) for categories that are not shares of a total.
- [Marks reference](/docs/spec/marks/) lists the channels and options each mark type takes.
