consolidated data per Jake's comments
Instead of having source in both the line, point calls (which necessitated calling transform on each),
Jake showed me that you can leave those empty, then provide the data and transform when you layer the plots together.
@@ -10,26 +10,23 @@ from vega_datasets import data
source = data.countries()
-line = alt.Chart(source).mark_line(color='#db646f').encode(
+line = alt.Chart().mark_line(color='#db646f').encode(
x = 'life_expect',
y = 'country',
detail = 'country'
).interactive()
-line.transform = [{'filter': {"field": 'country', "oneOf": ["China", "India", "United States", "Indonesia", "Brazil"]}},
- {'filter': {"field": 'year', "oneOf": [1955, 2000]}}]
-point = alt.Chart(source).mark_point(size = 100, opacity = 1, filled = True).encode(
+point = alt.Chart().mark_point(size = 100, opacity = 1, filled = True).encode(
x = 'life_expect',
y = 'country',
color=alt.Color('year:O',
scale=alt.Scale(
domain=['1955', '2000'],
range=['#e6959c', '#911a24']
- )))
+ )
+ )
+)
-point.transform = [{'filter': {"field": 'country', "oneOf": ["China", "India", "United States", "Indonesia", "Brazil"]}},
- {'filter': {"field": 'year', "oneOf": [1955, 2000]}}]
-
-chart = line + point
-#chart.transform = [{'filter': {"field": 'country', "oneOf": ["China", "India", "United States", "Indonesia", "Brazil"]}},
-# {'filter': {"field": 'year', "oneOf": [1955, 2000]}}]
+chart = alt.layer(line + point, data = source,
+ transform = [{'filter': {"field": 'country', "oneOf": ["China", "India", "United States", "Indonesia", "Brazil"]}},
+ {'filter': {"field": 'year', "oneOf": [1955, 2000]}}])
