This content applies to a previous version of CARTO
In October 2021 we released a new version of our platform. You can find the latest documentation at docs.carto.com
How to visualize more than ten categories
Overview
Category Maps, also called Qualitative Maps, are designed to visualize unique values in a data attribute. For instance, a dataset containing country names treats each unique name as a category. Since no category should appear more important than others, an ideal palette uses swatches with equal visual weight, such as CARTOColor schemes.
When using Style By Value in Builder to create a Category Map, up to 10 categories are given unique colors and the rest are bucketed into an “Other” category and colored gray.
Custom CartoCSS with Repeating Colors
If allowing some categories to share colors is acceptable, custom CartoCSS provides a solution. This approach involves writing conditional CartoCSS that defines specific colors for each category, enabling color reuse across different categories.
#layer {
polygon-fill: #b3b3b3;
[name = "Namibia"]{
polygon-fill: #9eb9f3;
}
[name = "Sierra Leone"]{
polygon-fill: #66c5cc;
}
// ... additional rules for each category
}
PostgreSQL Shortcut
A more efficient approach uses PostgreSQL with modulus to group countries and assign colors systematically:
SELECT cartodb_id, the_geom, the_geom_webmercator, name, cartodb_id % 11 as modulus
FROM africa_adm0
Then assign colors to each modulus value (0-10), reducing manual CartoCSS writing considerably.
CARTO VL Ramp
The simplest method uses CARTO VL’s ramp function for automatic color assignment: color: ramp($name, pastel). This automatically detects unique category values and assigns colors without manual intervention.
Aggregating Categories
For datasets with excessive categories, combine them into fewer groups using Builder’s Intersect and Aggregate analysis feature to simplify visualization.
