US counties shade/shuffle map

Updated 7 years ago by Template retirement home

How to use this template

Shade & shuffle map: US counties

Quickly create US counties maps. Compare one or more metrics with a nav or show change over time with a slider. The template gives control over shading and bucketing, and has a shuffle feature where counties can be animate to reveal those with the highest and lowest scores.

Credits

Hat tips to Mike Bostock (D3, D3 Chromatic, Topojson, US Atlas), Susie Wu (D3 legend) and Cynthia Brewer (ColorBrewer).

This section documents API usage specific to this template, so for an introduction we suggest you refer to the generic API documentation instead.

template: _88

version: _4

Template data

There are three different formats in which you can supply data to this template. The most convenient for you to use likely depends on the source of your data, as described below.

1. Array of arrays, and a bindings object

You can supply arrays of arrays to opts.data, which might look like:

{
    data: {
        data: [
            [ "DataColumn1Value1", "DataColumn2Value1",
            [ "DataColumn1Value2", "DataColumn2Value2",
            [ "DataColumn1Value3", "DataColumn2Value3",
            ...
        ]
    }
}

where each array of arrays represents the rows in a data sheet.

To tell the API how the values from each column should be associated with the keys that the template is expecting, you must also supply an object attached to opts.bindings. (The meanings of the keys in the bindings object are documented below.) The minimal bindings you can supply for this template are as shown in this example:

{
    template: "_88",
    version: "_4",
    bindings: {
        data: {
            id: 0, // index of a column in your data
            name: 1, // index of a column in your data
        }
    },
    data: {
        data: [
            [ "DataColumn1Value1", "DataColumn2Value1",
            [ "DataColumn1Value2", "DataColumn2Value2",
            [ "DataColumn1Value3", "DataColumn2Value3",
            ...
        ]
    }
}

All possible bindings that you can supply are shown in this example:

{
    template: "_88",
    version: "_4",
    bindings: {
        data: {
            id: 0, // index of a column in your data
            name: 1, // index of a column in your data
            values: [2, 3, ...], // index(es) of column(s) in your data
        }
    },
    data: {
        data: [
            [ "DataColumn1Value1", "DataColumn2Value1",
            [ "DataColumn1Value2", "DataColumn2Value2",
            [ "DataColumn1Value3", "DataColumn2Value3",
            ...
        ]
    }
}

2. Array of objects with arbitrary keys, and a bindings object

This format is most likely useful when you have data from an external source, such as CSV data loaded from d3-dsv. You should supply this attached to the opts.data, which might look like:

{
        data: [
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            ...
        ]
    }

... but with the keys being the column headers from your source data instead. You must also supply an object attached to opts.bindings. The minimal bindings you can supply for this template are as shown in this example:

{
    template: "_88",
    version: "_4",
    bindings: {
        data: {
            id: "DataHeader1",
            name: "DataHeader2",
        }
    },
    data: {
        data: [
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            ...
        ]
    }
}

All possible bindings that you can supply are shown in this example:

{
    template: "_88",
    version: "_4",
    bindings: {
        data: {
            id: "DataHeader1",
            name: "DataHeader2",
            values: ["DataHeader3", "DataHeader4", ...],
        }
    },
    data: {
        data: [
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            ...
        ]
    }
}

(As before, the keys containing "Header" would be replaced by column names from your data source.)

3. Array of objects with template-defined keys

There is an alternative format you can use, which is likely to be easier to use if your data is not from a spreadsheet source. With this alternative format you supply your data to the template as an array of objects, attached to opts.data, where the keys must be those used by the template, as documented below. In this case there is no need to supply a bindings object, since the key names are already those expected by the template. The required properties in the data object are as follows (scroll down for a description of what each property is):

{
    template: "_88",
    version: "_4",
    data: {
    data: [
        {
            id: ...,
            name: ...,
            values: [...]
        },
        ...
    ]
},
    ...
}

And the full list of all possible properties is as follows:

{
    template: "_88",
    version: "_4",
    data: {
    data: [
        {
            id: ...,
            name: ...,
            values: [...]
        },
        ...
    ]
},
    ...
}

Meanings of the template data keys:

  • data.id: The column containing the numerical id of the county
  • data.name: The column containing the name of the county
  • data.values: One or more columns of values. If you specify one or more, a nav will be created so the user can choose between the columns. You can choose from a slider, dropdown or button-style nav in the Navigation settings above.

Template settings

Options for opts.state.

Colour scheme

palette string

Palette. Specify a list of color codes seprated by commas, or a d3 sequential scheme (such as [[schemeOranges]], [[schemeReds]], [[schemeBlues]] and [[schemeGreens]]) or diverging scheme (such as [[schemeRdYlGn]] or [[schemePiYG]]). See github.com/d3/d3-scale-chromatic for a full list.

Colour buckets

buckets number

Number of buckets. From 3 to 9; ignored if using custom colors or thresholds

Min: 3

Max: 9

domain_min number

Color scale min.

domain_max number

Color scale max.

custom_thresholds string

Custom color thresholds. A comma-separated list of numbers defining the thresholds between the buckets. This overrides the number of buckets.

State borders

state_border_color color

Colour.

state_border_opacity number

Opacity.

Max: 1

state_border_width number

Width.

Missing data

no_data_fill color

Colour.

hatch boolean

Show as pattern.

Number styles

prefix string

Number prefix. Optional prefix for numbers; useful for currency symbols

suffix string

Number suffix. Optional suffix for numbers; useful for units

Shuffle mode

rank_mode boolean

Shuffle mode.

rank_number number

Number to highlight. The number of counties to animate in the shuffle mode

sort_order string

Sort order. Specify [[ascending]] or [[descending]].

Nav type. Specify [[Buttons]], [[Slider]] or [[Dropdown]]. Ignored if you've only selected one column for values.