CartoDB (recently rebranded to CARTO) is a web-based mapping platform that offers GIS and web mapping tools to build maps for display and interaction in browsers. CartoDB excels at building thematic maps. Signing up through CartoDB is free for small accounts, and your instition may have a subscription to CartoDB if you require more than the freemium level.

Examining the data

For working with CartoDB, let’s use the historic U.S. cities population data compiled by Erik Steiner at the Spatial History Project in the Center for Spatial and Textual Analysis. You can download a modified and tidy version of the data as a CSV from here. Be sure to read the repository where this data comes from, which explains how the data was collected by Erik and what the data is attempting to describe.

Open the file in Libre Office or Excel. What kind of spatial data is included here?

Uploading data to CartoDB

We are going to start by connecting our dataset to CartoDB. Click on “New Map” in the upper right corner, select “Connect Dataset,” make sure that “Data file” is selected and browse for the us-historical-populations-tidy.csv file on your desktop. Note we can also connect data in other ways. If you wanted, you could connect the data to a Google Spreadsheet. So, if you’re planning to make continuous edits to the data and want that reflected nearly instantaneously with the map, that might be a good option for you. Or, if much of your data already lives in Google Spreadsheets, you might as well use that instead of exporting the data.

Connecting data in CartoDB.

Connecting data in CartoDB.

Once you’ve imported the data, you’ll be presented with a map right away without any special styling.

The default map.

The default map.

We want to do some interesting things with this data, since viewing this map alone isn’t that informative. We could, for example, create a bubble map of the population data. Selecting the map layer wizard on the righthand side and scroll to the “Bubble” map. Try changing some of the aesthetic features of the map (bubble sizing, color, stroke width, and so on).

Bubble map of populations.

Bubble map of populations.

But our data includes much more than just population figures. We have three important variables to map: the population of a city in a given year. CartoDB has a feature that makes it relatively easy to make a map that allows you to visualize change over time using what they call “Torque.” Select Torque from the map layer wizard and let’s see what we get.

Torque map of populations.

Torque map of populations.

We can adapt our torque map to be more interesting by applying some CartoCSS to the map, changing the size of the bubbles based on the population count in each city. The code below will allow us to do that.

Map {
-torque-frame-count:128;
-torque-animation-duration:10;
-torque-time-attribute:"year_clean";
-torque-aggregation-function:"count(population)";
-torque-resolution:1;
-torque-data-aggregation:cumulative;
}

#us_population{
  comp-op: source-over;
  marker-fill-opacity: 1;
  marker-line-color: #FFF;
  marker-line-width: 1;
  marker-line-opacity: 1;
  marker-type: ellipse;
  marker-width: 2;
  marker-fill: #F84F40;
}

#us_population[value>2]{
  marker-width: 3;
}
#us_population[value>4]{
  marker-width: 4;
}
#us_population[value>6]{
  marker-width: 5;
}
#us_population[value>8]{
  marker-width: 7;
}
#us_population[value>10]{
  marker-width: 8;
}
#us_population[value>12]{
  marker-width:10;
}
#us_population[value>14]{
  marker-width: 12;
}

The problem? It’s not a very interesting map.

Pet peeves.

Pet peeves.

Next steps

Spend some time trying to map your own dataset, or check out some of the datasets available through CartoDB. Create a different map using one of these datasets. What sorts of aesthetics are appropriate for these data?

You can also join additional data in CartoDB. Read about joining two datasets together following CartoDB’s tutorial for joining data.