10  Distributions

10.1 Bar Plots

10.1.1 A simple bar plot

df |> 
    ggplot(aes(gen_health)) +
    geom_bar(color = "red")

sns.countplot(x="gen_health", color="grey", edgecolor="red", data=df)

10.1.2 A stacked bar plot

df |> 
    ggplot(aes(gen_health, fill = heart_disease)) +
    geom_bar()

sns.displot(x="gen_health", hue="heart_disease", multiple="stack", aspect=7/5, data=df);
plt.show()

10.1.3 A dodged bar plot

df |> 
    ggplot(aes(gen_health, fill = heart_disease)) +
    geom_bar(position = "dodge")

sns.countplot(x="gen_health", hue="heart_disease", data=df)

10.2 Histograms

df |> 
    ggplot(aes(bmi)) +
    geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

sns.histplot(x="bmi", data=df)

10.3 Density Plots

df |> 
    ggplot(aes(bmi)) +
    geom_density()

sns.kdeplot(x="bmi", data=df)

10.4 Boxplots

df |> 
    ggplot(aes(smoking, bmi)) +
    geom_boxplot()

sns.boxplot(x="smoking", y="bmi", data=df)

10.5 Violin Plots

df |> 
    ggplot(aes(smoking, bmi)) +
    geom_violin()

sns.violinplot(x="smoking", y="bmi", data=df)