November 17, 2016
Michelle Ho, [email protected]
Mehak Sachdeva, [email protected], @MehakSachdeva_
This link is here: http://bit.ly/1117-yale
- It depends on how you use it ;)
- Geo data matters
- Urban Reviewer
- Tweets mentioning sunrise
- Carto Calculator
- Evictions in San Francisco
- L Train project
- Other projects
- NYC Henge
- Animated maps to compliment analysis: http://toddwschneider.com/posts/analyzing-1-1-billion-nyc-taxi-and-uber-trips-with-a-vengeance/
- Our L Train analysis: https://carto.com/blog/looking-at-the-l/
- Ben Wellington:
Welcome to CARTO Builder!
A peek at the final map for the first session:
For this map, we are using the same data as the Guardian. We went through several steps to grab the raw data and join it with county and/or congressional districs (based on the reporting unit). We are also using some reference layers for state boundaries and labels.
To start, add the following layers:
Let's take a look at what attributes we have in the data.
- To follow the NY Times inspiration map, we calculated the percentage votes for each party as well as the county winner (democratic or republican) for each reporting unit
- For this map we will symbolize two variables
- The county winner for each unit (
county_winner
) - And using a color ramp, the percentage of votes for each party (
pct_dem
andpct_gop
)
- Let's start by styling our choropleth map
- Click on the Style tab
- Style by value
- Search for
pct_dem
- Set the number of classes to 4 and we'll keep the quantification method as 'Equal Interval'
You can also read more about various tools in Carto in our new Learn!
Our final map uses the red ramp for Republican Party and a Blue ramp for Democratic party. Let's go to the CartoCSS editor to see what has been populated based on our styling choices.
- In Builder, we are using TurboCarto a CartoCSS preprocessor
polygon-fill
is where our classification is happening- In order to symbolize Democratic and Republican(referred as 'dem' and 'gop' in our dataset) using two different ramps, we'll do the following:
#layer {
line-width: 1;
line-color: #FFF;
line-opacity: 0.5;
[county_winner = 'dem'] {
polygon-fill: ramp([pct_dem], (#CCFDFE, #6193C7, #9CC0E3, #006AAB), equal);
}
[county_winner = 'gop'] {
polygon-fill: ramp([pct_gop], (#FBD0D0, #E99D99, #CF615D, #B02029), equal);
}
}
- Click Apply to see the map update
Ok! So now we have a map that shows which counties the Democrats won and which counties the Republicans won. The darker the color, the higher the percentage of votes in that county.
- We'll make a couple of more modifications to our CartoCSS to polish the map
- we'll remove the
line-
properties because we are looking at different reporting units - and we'll set some of the
polygon-
properties as follows
#layer {
polygon-gamma: 0.4;
polygon-opacity: 0.9;
[county_winner = 'dem'] {
polygon-fill: ramp([pct_dem], (#CCFDFE, #6193C7, #9CC0E3, #006AAB), equal);
}
[county_winner = 'gop'] {
polygon-fill: ramp([pct_gop], (#FBD0D0, #E99D99, #CF615D, #B02029), equal);
}
polygon-fill: #d3d3d3;
}
- Next, we'll change the basemap to Positron Lite
- in the Layer view, click on the bottom basemap layer and choose Positron lite
- Next, we'll style our state boundary lines
- in the Style tab, we'll set the
line-width
to1
and theline-color
to#FFFFFF
- And finally, let's label the state points using the following settings
-
Download the Education Dataset
-
In order to add demographic context to this election, we have prepared a dataset from the CARTO Data Observatory that contains educational attainment for US counties. We have chosen to focus on white male and white female educational attainment for this exercise. You can grab more census variables from another data repository like the Data Observatory, Social Explorer (http://www.socialexplorer.com/), or directly from the Census if you like.
-
We want to add several widgets to our map that show total numbers of white male educational attainment. However, these are raw numbers currently. Let's divide by the total population to get percentages. For example:
ALTER TABLE education_by_race_county
ADD COLUMN male_less_than_HS_pct numeric,
ADD COLUMN male_HS_pct numeric,
ADD COLUMN male_some_college_pct numeric,
ADD COLUMN male_bachelors_pct numeric;
UPDATE education_by_race_county
SET male_less_than_HS_pct = 100 * total_male_less_than_high_school_diploma/(total_male);
UPDATE education_by_race_county
SET male_HS_pct = 100 * total_male_high_school_graduate_includes_equivalency/(total_male);
UPDATE education_by_race_county
SET male_some_college_pct = 100 * total_male_some_college_or_associates_degree/(total_male);
UPDATE education_by_race_county
SET male_bachelors_pct = 100 * total_male_bachelors_degree_or_higher/(total_male);
- On the election_results layer (which should now have polygons), join the education data layer. Keep all columns from both layers.
Join the county shapes layer with the election results map you just created
County Shapes Layer > Add Analysis > Join columns from 2nd layer
-
Select the election results layer as the second layer, and use foreign keys "geoid" and "fips"
-
Use geometries from the county shapes layer, and keep the name column from county shapes and all columns from election results
-
Add histogram widgets to explore and query the map by educational attainment
[Final Map] (https://michellemho.carto.com/builder/2585e4f8-ab7f-11e6-be52-0ef7f98ade21/embed)
You can continue to ask more questions with the election data joining it with other demographic level data and create more interesting dashboards!
- Proportional Symbol Map
- [Shift in Margin Map] (https://team.carto.com/u/mehak-carto/builder/f1913d6e-a764-11e6-a960-0ecd1babdde5/embed)
- Get on GitHub Student Developer Packs if you can
- "student accounts": https://carto.com/signup?plan=academy
- SQL API (write sql, get data via HTTP requests)
- Data Services API
- Geocoding, routing, etc.
- Nice demos here: https://carto.com/location-data-services/
- Data Observatory API
- Functions for getting measures (World censuses, Zillow, etc.)
- Functions for getting boundaries
- Catalog of available data: https://cartodb.github.io/bigmetadata/index.html
- Find things like median income at our location:
SELECT OBS_GetMeasure(CDB_LatLng(40.7529671,-73.9927947), 'us.census.acs.B19013001'::text)
- Explain Subway stops: https://jkrauss.carto.com/builder/18644096-65c3-11e6-adbe-0ee66e2c9693/embed
- Maps API
- For fetching map tiles for use with Google Maps API, Leaflet.js, OpenLayers, etc.
- Generating dynamically made image previews (aka, static maps)
- For example: http://mamataakella.carto.com/api/v1/map/static/named/tpl_25aaad68_7134_11e6_afae_0e3ebc282e83/1600/1600.png?zoom=5&lat=40.7529777&lon=-73.994722
- Import API
- Send data to your CARTO account
- Setup sync tables (responsive to upstream changes to data so you can create dynamic maps)
- Spatial Analysis
- geo-statistics using PySAL, scikit-learn, and others
- tons more coming soon
- Carto.js -- workhorse library for building custom applications off of CARTO's platform
- Torque.js -- create spatio-temporal maps from your time-series data
- r2cartodb: https://rpubs.com/walkerke/r2cartodb
- CARTO's Python Client: https://github.com/CartoDB/carto-python
- R's
read.csv
and Panda'sread_csv
work with our SQL API when theformat
flag is set tocsv
- Format:
http://eschbacher.carto.com/api/v2/sql?q=SELECT * FROM awesome_table&format=csv
- Use with Plotly: https://plot.ly/ipython-notebooks/cartodb/
- Format:
- DC Elevation App -- see index.html on this gist
- Charts!
- We made this at a little meetup we run in our office last week