I managed to create a scatterplot using seaborn and matplotlib where I have the continuous variable LifeExp
on the y-axis and the categorical variable continent
on the x-axis, and I plotted the life expectancy for the 3 different continents (with some jitter). I would like now to add a segment for the mean of each continent.
Here is the code and the plot generated:
from gapminder import gapminder
import seaborn as sns
import matplotlib.pyplot as plt
gapminder_2007 = gapminder.loc[gapminder['year'] == 2007]
gapminder_3_continents = gapminder_2007.loc[(gapminder_2007['continent'] == "Europe") | (gapminder_2007['continent'] == "Americas") | (gapminder_2007['continent'] == "Africa")]
fig, ax = plt.subplots(figsize =(7, 5))
sns.set(style='ticks', context='talk')
sns.stripplot('continent', 'lifeExp', data=gapminder_3_continents, jitter=0.2)
sns.despine()
plt.axhline(y=gapminder_3_continents["lifeExp"].mean(), color='green', ls='-')