Hey! This content applies only to previous CARTO products

Please check if it's relevant to your use case. On October 2021 we released a new version of our platform.
You can learn more and read the latest documentation at docs.carto.com

Tutorials  /  Map Styling  /  Guides

Example - Advanced Cartography in CARTO Builder

You asked about defining custom class breaks and using a custom color scheme. TurboCARTO won’t solve the frustratiion of having to copy/paste the styling to multiple maps or the current inability to save custom colors and schemes. But it will definitely help streamline the process.

TurboCARTO

Based on the workflow you described, I think you will find TurboCARTO super useful. In essence, TurboCARTO is to data driven thematic map design what CartoCSS is to multi-scale basemap design.

There are many advantages to using TurboCARTO but two that stand out most for me are:

  • The ease in which you can make various types of thematic maps. What used to takes lines of CartoCSS, is now a line of code using TurboCARTO
  • If your data updates, your map updates. With traditional CartoCSS, the code for a choropleth map hard-codes class breaks. With this model, if your data updates, you would have to go back, and reclassify your map to account for the new data. With TurboCARTO, if your data updates, your classification automatically updates, and in turn your map. This is SO COOL!

Resources:

Here are a couple of intro resources (more advanced coming soon):

Example:

If you make a thematic map through the wizards (like choropleth or a proportional symbol), in addition to the basic CartoCSS styling, you will also see CartoCSS properties written with TurboCARTO syntax.

This is a map of commuter flow between counties in New York state.

screen shot 2017-01-11 at 10 56 24 am

The map is styled on an attribute commuters_in_flow. Using this attribute, we are varying both the line-width (from 0.3 - 2) and line-color (using a default sequential CARTOColor scheme).

This is done using the default form in Builder:

screen shot 2017-01-11 at 11 08 33 am

If you look over to the CartoCSS pane, you will see the following:

#layer {
  line-width: ramp([workers_in_flow], range(0.3, 2), quantiles(7));
  line-color: ramp([workers_in_flow], (#074050, #105965, #217a79, #4c9b82, #6cc08b, #97e196, #d3f2a3), quantiles(7));
  line-comp-op: lighten;
}

Which means:

  line-width:
  - using the quantiles method with 7 class breaks,
  - vary the line-width between 0.3-2
  - by number of workers in each flow

  line-color:
  - using the quantiles method with 7 class breaks,
  - vary the line-color over these sequential colors
  - by number of workers in each flow (reads low to high)

  line-comp-op:
  - lighten compositing operation

Now if I wanted to use Uber’s sequential palette, I would modify the TurboCARTO for line-color to:

   line-color: ramp([workers_in_flow], (#108188,#339198,#4ca2a8,#62b4b9,#79c5ca,#8ed7da,#a3e9ec), quantiles(7));

Which would look like:

screen shot 2017-02-02 at 12 55 53 pm

Manual Classification

You mentioned one of the things you do often is find the breaks in your data and apply manual classification. You can do that with TurboCARTO as well.

Using the example above,

  • I want to make 7 manual class breaks using the workers_in_flow attribute
  • My class breaks are 100,500,1000,2000,3000,5000,7000
  • The 7 sequential colors I want to use are #074050, #105965, #217a79, #4c9b82, #6cc08b, #97e196, #d3f2a3 (dark colors for low values and light color for high values because we are on a dark background)
  • Using the "<" mapping (you can also use other mappings like >,=>,<=,=)

The TurboCARTO syntax for this would be:

line-color: ramp([workers_in_flow], (#074050, #105965, #217a79, #4c9b82, #6cc08b, #97e196, #d3f2a3), (100,500,1000,2000,3000,5000,7000), "<");

With the result below. You will notice that the line-width is fixed since we are only defining that color vary based on the number of commuters.

screen shot 2017-02-02 at 1 22 31 pm

Projections

You mentioned that your cartographers (rightly so!) have requested appropriate projections for small scale maps of the country or world.

Projections are possible in CARTO. The one caveat is that at this time, widgets do not work with projected data. That is because they function in the Web Mercator space and not in a projected one.

Resources

Example

You will get a lot from the resources above in terms of the different projections, how to use them in CARTO, etc. But here is a quick example of projecting US Roads to Albers.

The basic query for projections looks like this:

SELECT
  ST_Transform(the_geom_webmercator,5070)
AS
  the_geom_webmercator,
  the_geom,
  cartodb_id
FROM
  ne_10m_roads
  • ST_Transform(the_geom_webmercator,5070) as the_geom_webmercator is basically saying, use the SRID for Albers to draw the data instead of Web Mercator (which is the default)
  • You will also need to select the_geom and cartodb_id
  • From your table name

The result for the roads would be:

screen shot 2017-02-02 at 1 54 49 pm

If you want to color the roads by the attribute type you need to select that as well:

SELECT
  ST_Transform(the_geom_webmercator,5070)
AS
  the_geom_webmercator,
  the_geom,
  cartodb_id,
  type
FROM
  mamataakella.ne_10m_roads

Result (after styling):

screen shot 2017-02-02 at 1 57 45 pm

To change the background color of the map, click on the Postitron Basemap layer in your layer list:

screen shot 2017-02-02 at 2 10 31 pm

With some other modifications like only selecting roads indside the US, and applying the same projection information to a US polygon, I get this final map.

screen shot 2017-02-02 at 2 07 02 pm

Zoom dependent styling

Another question you had was about zoom dependent styling. Basically, as you zoom in, how can you control the size of features.

If you can provide a specific example, I can help with the syntax if needed. Below, are some basics for zoom level and conditional styling. You can do some pretty complex things with the right rules.

If you are making a thematic map, you can use the syntax below with TurboCARTO as well.

Resources:

Example:

The basic CartoCSS syntax for zoom dependent styling is this:

#layer {
  line-width: 7;
  line-color: #000;

  [zoom>5]{
    line-width: 9;
    line-color: red;
  }

  [zoom>7]{
     line-width: 12;
     line-color: orange;
  }

   [zoom>9]{
     line-width: 15;
     line-color: yellow;
  }
 }

You can define a range of zooms for a particular style:

 #layer {
    line-width: 10;
    line-color: #000;

    [zoom>=5][zoom<=7]{
      line-width: 9;
      line-color: red;
    }
 }

You can define a range of zooms that a layer draws:

 #layer [zoom>=3][zoom<=7] {
    line-width: 5;
    line-color: #000;
 }

You can also use conditional statements:

  #layer {
    line-width: 10;
    line-color: #000;

    [zoom>=5]{
      [type = 'Major Road']{
       line-width: 9;
       line-color: red;
      }
      [type = 'Minor Road']{
       line-width: 5;
       line-color: orange;
      }
    }
 }