""" Repeated Choropleth Map ======================= Three choropleths representing disjoint data from the same table. """ # category: geographic import altair as alt from vega_datasets import data pop_eng_hur = alt.UrlData(data.population_engineers_hurricanes.url) states = alt.UrlData(data.us_10m.url, format=alt.TopoDataFormat(type='topojson', feature='states')) variable_list = ['population', 'engineers', 'hurricanes'] chart = alt.Chart(states).mark_geoshape().properties( projection={ 'type': 'albersUsa' }, width=500, height=300).transform_lookup( lookup='id', from_=alt.LookupData(pop_eng_hur, 'id', variable_list)).encode( color=alt.Color(alt.repeat('row'), type='quantitative')).repeat( row=variable_list).resolve_scale(color='independent')
""" London Tube Lines ================= This example shows the London tube lines against the background of the borough boundaries. It is based on the vega-lite example at https://vega.github.io/vega-lite/examples/geo_layer_line_london.html. """ # category: geographic import altair as alt from vega_datasets import data boroughs = alt.UrlData(url=data.londonBoroughs.url, format=alt.TopoDataFormat(type='topojson', feature='boroughs')) centroids = data.londonCentroids.url tubelines = alt.UrlData(url=data.londonTubeLines.url, format=alt.TopoDataFormat(type='topojson', feature='line')) background = alt.Chart(boroughs).mark_geoshape( stroke='white', strokeWidth=2).encode(color=alt.value('#eee'), ).properties(width=700, height=500) labels = alt.Chart(centroids).mark_text().encode( longitude='cx:Q', latitude='cy:Q', text='bLabel:N', size=alt.value(8), opacity=alt.value(0.6)
""" Choropleth Map ============== A choropleth map of unemployment rate per county in the US """ # category: geographic import altair as alt from vega_datasets import data unemp_data = alt.UrlData(data.unemployment.url) counties = alt.UrlData(data.us_10m.url, format=alt.TopoDataFormat(type='topojson', feature='counties')) chart = alt.Chart(counties).mark_geoshape().properties( projection={ 'type': 'albersUsa' }, width=500, height=300).encode(color='rate:Q').transform_lookup( lookup='id', from_=alt.LookupData(unemp_data, 'id', ['rate']))
def geography(self): return alt.InlineData( values=util.get_geojson_resource('municipalities.topojson'), format=alt.TopoDataFormat(type='topojson', feature='municipalities'))
) shape_url = "https://raw.githubusercontent.com/austinorr/ca_metrics/master/data/ca-counties.json" columns = [ "grocery_pct", "gas_pct", "bank_pct", "doc_pct", "dent_pct", "hair_pct", ] CA_map = (alt.Chart( alt.Data(url=shape_url, format=alt.TopoDataFormat( feature="data", type="topojson"))).mark_geoshape(stroke="white").encode( color=alt.condition( selector_map, alt.Color("properties.region:N", scale=alt.Scale(scheme="category20")), alt.value("lightgray"), ), tooltip=[ alt.Tooltip("properties.name:N", title="County"), alt.Tooltip("properties.region:N", title="Region"), ], ).add_selection(selector_map).properties(width=500, height=800)) bar_chart = (alt.Chart(