Line plots
line_df = gapminder.query(" country == 'Malawi' ")
(ggplot(line_df, aes(x='year', y='lifeExp')) + bbc_style() +
geom_line(colour='#1380A1', size=1) +
geom_hline(yintercept=0, size=1, colour='#333333') +
labs(title='Living longer',
subtitle='Life expectancy in Malawi 1952-2007')
)
# altair
line = (alt.Chart(line_df).mark_line().encode(
x=alt.X('year', axis=alt.Axis(values=list(range(1950, 2020, 10)))),
y=alt.Y('lifeExp', axis=alt.Axis(values=list(range(0, 60, 10)))))
.properties(title={'text': 'Living Longer',
'subtitle': ['Life expectancy in Malawi 1952-2007'],
}, )
)
# hline
overlay = pd.DataFrame({'lifeExp': [0]})
hline = (
alt.Chart(overlay)
.mark_rule(color='#333333', strokeWidth=3)
.encode(y='lifeExp')
)
(line + hline).configure_axisX(grid=False)