Accumulation works by aggregating data per pixel during a backend render. Data is accumulated for every pixel for every shape rendered. Accumulation rendering is activated through color scales – scales that have colors defined for their range.
Note: Currently, only the COUNT aggregation function is supported.
This topic describes accumulation rendering and provides some implementation examples. The data source used here – a table called contributions
– contains information about political donations made in the New York City area, including party affiliation, the amount of the donation, and location of the donor.
There are three accumulation modes:
Density accumulation performs a count aggregation by pixel. It allows you to color a pixel by normalizing the count and applying a color to it, based on a color scale. In Heavy Immerse, if you open or create a Pointmap chart, you can toggle density accumulation on and off by using the Density Gradient attribute. For more information, see Pointmap.
Note: Blend and percentage accumulation are not currently available in Heavy Immerse.
The density mode examples use the following base code:
This code generates the following image:
All points are rendered with a size of 2 and colored according to the contribution amount:
$100 or less is colored blue.
$10,000 or more is colored red.
Anything in between is colored somewhere between blue and red, depending on the contribution. Amounts closer to $100 are more blue, and amounts closer to $10,000 are more red.
The examples that follow adjust the pointcolor
scale and show the effects of various adjustments. Any changes made to Vega code are isolated to that scale definition.
Density accumulation can be activated for any scale that takes as input a continuous domain (linear
, sqrt
, pow
, log
, and threshold
scales) and outputs a color range. In the following code snippet, the density accumulator has been added to the linear pointcolor
scale:
The final color at a pixel is determined by normalizing the per-pixel aggregated counts and using that value in the scale function to calculate a color. The domains of density accumulation scales should be values between 0 and 1 inclusive, referring to the normalized values between 0 and 1. The normalization is performed according to the minDensityCnt
and maxDensityCnt
properties. After normalization, minDensityCnt
refers to 0 and maxDensityCnt
refers to 1 in the domain. In this case, 0 in the domain equates to a per-pixel count of 1, and 1 in the domain equates to a per-pixel count of 100.
minDensityCnt
and maxDensityCnt
are required properties. They can have explicit integer values, or they can use keywords that automatically compute statistical information about the per-pixel counts. Currently available keywords are:
min
max
1stStdDev
2ndStdDev
-1stStdDev
-2ndStdDev
If you change the color scale to the following:
The minimum aggregated count of all the pixels is used as the minDensityCnt
, and the maximum aggregated count used as the maxDensityCnt
. This results in the following:
Notice that the area with the most overlapping points is in the upper east side of Manhattan.
Now, use +/- 2 standard deviations for your counts:
This produces the following:
In this example, the scale is changed to a threshold scale, and the colors are adjusted to create a more interesting image:
This results in:
Note: You can mix and match explicit values and keywords for minDensityCnt
and maxDensityCnt
. However, if your min
value is greater than your max
value, your image might look inverted.
Blend accumulation works only with ordinal scales. This accumulation type blends the per-category colors set by an ordinal scale so that you can visualize which categories are more or less prevalent in a particular area.
The following Vega code colors the points according to the value in the recipient_party
column:
This results in the following chart:
Each point is colored according to recipient party. Values of R
(republican) are colored red, D
(democrat) are colored blue, and everything else is colored green.
To activate blend accumulation, add the "accumulator": "blend"
property to an ordinal scale.
This generates the following chart:
Activating blend accumulation shows you where one party is more dominant in a particular area. The COUNT aggregation is now being applied for each category, and the colors associated with each category are blended according to the final percentage of each category per pixel.
Note: Unlike in density mode, a field
property is required in mark
properties that reference blend accumulator scales.
Percentage (pct
) mode can help you visualize how prevalent a specific category is based on a percantage. Any scale can be used in percentage mode, but the domain values must be between 0 and 1, where 0 is 0% and 1 is 100%.
Using the political donations database, you can determine where the recipient_party
of “R” (republican) is more prevalent.
Here’s the color scale:
And the resulting image:
Using the threshold scale, anything colored blue is between 0%-33% republican, purple is 33%-66% republican, and red is 66%-100% republican.
pctCategory
is a required property for percentage mode and can be numeric or a string. A string refers to a string value from a dictionary-encoded column.
You can modify the example to use a numeric value for pctCategory. First, modify the SQL in the Vega to select the contribution amount for each data point:
Now use the amount as the driving field for the pct
accumulator scale:
Now, change the pct
scale to the following:
This results in the following output, showing where thousand-dollar contributions are most prevalent:
You can use the pctCategoryMargin
property to buffer numeric pctCategory
values, so you can use a range for the numeric category.