Plot all of your data: Bee swarm plots

Statistical Thinking in Python (Part 1)

Justin Bois

Teaching Professor at the California Institute of Technology

2008 US swing state election results

ch1-3.003.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

2008 US swing state election results

ch1-3.005.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Binning bias

  • The same data may be interpreted differently depending on choice of bins
Statistical Thinking in Python (Part 1)

Bee swarm plot

ch1-3.009.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Organization of the data frame

ch1-3_v2.011.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Organization of the data frame

ch1-3_v2.012.png

Statistical Thinking in Python (Part 1)

Organization of the data frame

ch1-3_v2.013.png

Statistical Thinking in Python (Part 1)

Generating a bee swarm plot

_ = sns.swarmplot(x='state', y='dem_share', data=df_swing)
_ = plt.xlabel('state')
_ = plt.ylabel('percent of vote for Obama')
plt.show()
Statistical Thinking in Python (Part 1)

2008 US swing state election results

ch1-3_v2.018.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Let's practice!

Statistical Thinking in Python (Part 1)

Preparing Video For Download...