Xuliqin The homework5

import pandas as pd
url ='https://raw.githubusercontent.com/tidyverse/datascience-box/refs/heads/main/course-materials/lab-instructions/lab-02/data/plastic-waste.csv'
df = pd.read_csv(url)
df
code entity continent year gdp_per_cap plastic_waste_per_cap mismanaged_plastic_waste_per_cap mismanaged_plastic_waste coastal_pop total_pop
0 AFG Afghanistan Asia 2010 1614.255001 NaN NaN NaN NaN 31411743.0
1 ALB Albania Europe 2010 9927.181841 0.069 0.032 29705.0 2530533.0 3204284.0
2 DZA Algeria Africa 2010 12870.602699 0.144 0.086 520555.0 16556580.0 35468208.0
3 ASM American Samoa Oceania 2010 NaN NaN NaN NaN NaN 68420.0
4 AND Andorra Europe 2010 NaN NaN NaN NaN NaN 84864.0
... ... ... ... ... ... ... ... ... ... ...
235 VNM Vietnam Asia 2010 4408.168612 0.103 0.090 1833819.0 55858245.0 87848445.0
236 ESH Western Sahara Africa 2010 NaN NaN NaN NaN NaN 530500.0
237 YEM Yemen Asia 2010 4478.743599 0.103 0.077 169181.0 6048920.0 NaN
238 ZMB Zambia Africa 2010 3279.277161 NaN NaN NaN NaN 13088570.0
239 ZWE Zimbabwe Africa 2010 1474.877128 NaN NaN NaN NaN 12571454.0

240 rows × 10 columns

import pandas as pd
from lets_plot import *

LetsPlot.setup_html()
(
  ggplot(df, aes("continent", "plastic_waste_per_cap")) +
  geom_histogram()
)
(
  ggplot(df, aes("continent", "plastic_waste_per_cap"))
  + geom_boxplot()
)
import seaborn as sns
import matplotlib.pyplot as plt

# 利用violinplot函数绘制小提琴图
sns.violinplot(x=df["continent"], y=df["plastic_waste_per_cap"])

plt.show()

(
    ggplot(df, aes("plastic_waste_per_cap", "mismanaged_plastic_waste_per_cap")) +
  geom_point()
)
(
    ggplot(
        df,
        aes(
            "plastic_waste_per_cap",
            "mismanaged_plastic_waste_per_cap",
            colour="continent",
        ),
    )
    + geom_point()
)
(
    ggplot(df, aes(x="total_pop", y="plastic_waste_per_cap", colour="continent"))
    + geom_point()
    + xlim(0, 150000000)
    + ylim(0, 0.8)
)
(
    ggplot(df, aes(x="coastal_pop", y="plastic_waste_per_cap", colour="continent"))
    + geom_point()
    + xlim(0, 50000000)
    + ylim(0, 0.8)
)