1

I'm extremely new to CARTO and I'm still learning the ropes. I currently have this territory map where the colors represent a representative in a county.

Territory map

However, it isn't shading the 36 total representatives. It only shades 10 then groups the other 26 in Others.

This is my current layer style setup in Builder:

enter image description here

All I want to be able to do is a have a color for every representative and not have the Others category. I read that I may have to do something with CartoCSS, but it didn't guide me in the right direction.

What's the best way to go about this? If there's a better way for me to visualize what I'm trying to accomplish, please tell me.

I'm running CARTO self-hosted.

2

You were on the right track. In order to style all your categories using CARTO Builder, you need to switch from values to CartoCSS as shown in the following gif:

value-to-cartocss

Secondly, you need to update the code using basic CartoCSS conditionals. Notice that you would need to know the category names and colors in advance. You can use a code like this one.

#layer {
  polygon-fill: #666666;
  [ name = "Afghanistan" ] {
    polygon-fill: #5F4690;
  }
  [ name = "Åland Islands" ] {
    polygon-fill: #1D6996;
  }
  [ name = "Albania" ] {
    polygon-fill: #38A6A5;
  }
  [ name = "Algeria" ] {
    polygon-fill: #0F8554;
  }
  [ name = "American Samoa" ] {
    polygon-fill: #73AF48;
  }
  [ name = "Andorra" ] {
    polygon-fill: #EDAD08;
  }
  [ name = "Angola" ] {
    polygon-fill: #E17C05;
  }
  [ name = "Anguilla" ] {
    polygon-fill: #CC503E;
  }
  [ name = "Antarctica" ] {
    polygon-fill: #94346E;
  }
  [ name = "Antigua and Barbuda" ] {
    polygon-fill: #6F4070;
  }
}
#layer::outline {
  line-width: 1;
  line-color: #FFFFFF;
  line-opacity: 0.5;
}

On the other hand, this problem could be easily overcome using just one line of code of CARTO VL as explained in this example:

color: ramp($name, vivid)

Link to the working example here.

carto-vl-viz

What CARTO VL is doing behind the scenes is interpolating the colors when the 10 categories are reached.

2

You have the correct idea that CartoCSS is something that would assist in this effort of yours. I believe the color ramp will generally work with about 7 or so colors before it lumps everything else in the "Other" category.

I would suggest referencing Tips & Tricks - Geospatial Analysis

SELECT cartodb_id,
   the_geom,
   the_geom_webmercator,
   cartodb_id % 36 as modulus       
 FROM populated_places

Using the modulus, you can input your each of the fills as such

#layer {
marker-width: 3;
marker-fill-opacity: 2;
marker-allow-overlap: false;
marker-line-width: 1;

[modulus=0]{marker-fill: #73AF48;}
[modulus=1]{marker-fill: #CC503E;}
.
.
.
[modulus=36]{marker-fill: #0F8554;}    
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.