Data weekend:Global Plastic Waste

栏目: 编程工具 · 发布时间: 5年前

内容简介:PHOTOGRAPHS BY RANDY OLSON

Data weekend:Global Plastic Waste

PHOTOGRAPHS BY RANDY OLSON

开篇

上海市垃圾分类立法 在

2019年7月1日起施行。个人混投垃圾最高可罚200元,单位混装混运最高可罚5万元。丢垃圾要分为4类:

    1. 可回收物 :废纸张、废塑料、废玻璃制品、废金属、废织物等
    1. 有害垃圾 :废电池、废灯管、废药品、废油漆及其容器等
    1. 湿垃圾 :食材废料、剩菜剩饭、过期食品、瓜皮果核、花卉绿植等
    1. 干垃圾 :除可回收物、有害垃圾、湿垃圾以外的其它生活废弃物

《上海市生活垃圾管理条例》同时规定:旅馆不得主动提供客房一次性日用品。餐饮服务不得主动提供一次性餐具。

package

library(tidyverse)
library(dplyr)
library(scales)
library(ggplot2)
library(readr)
library(janitor)
library(ggthemes)
theme_set(theme_light())

导入数据

coast_vs_waste <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-05-21/coastal-population-vs-mismanaged-plastic.csv")

mismanaged_vs_gdp <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-05-21/per-capita-mismanaged-plastic-waste-vs-gdp-per-capita.csv")

waste_vs_gdp <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-05-21/per-capita-plastic-waste-vs-gdp-per-capita.csv")
# data source shttps://ourworldindata.org/plastic-pollution
global_plastics_production=read_csv("https://raw.githubusercontent.com/TonyFly3000/kaggle/master/global-plastics-production.csv")
global_plastics_production
## # A tibble: 66 x 4
##    Entity Code      Year `Global plastics production (million tonnes) (ton~
##    <chr>  <chr>    <int>                                              <int>
##  1 World  OWID_WRL  1950                                            2000000
##  2 World  OWID_WRL  1951                                            2000000
##  3 World  OWID_WRL  1952                                            2000000
##  4 World  OWID_WRL  1953                                            3000000
##  5 World  OWID_WRL  1954                                            3000000
##  6 World  OWID_WRL  1955                                            4000000
##  7 World  OWID_WRL  1956                                            5000000
##  8 World  OWID_WRL  1957                                            5000000
##  9 World  OWID_WRL  1958                                            6000000
## 10 World  OWID_WRL  1959                                            7000000
## # ... with 56 more rows

数据清洗

coast_vs_waste%>%glimpse()
## Observations: 20,093
## Variables: 6
## $ Entity                              <chr> "Afghanistan", "Afghanista...
## $ Code                                <chr> "AFG", "AFG", "AFG", "AFG"...
## $ Year                                <int> 1800, 1820, 1870, 1913, 19...
## $ `Mismanaged plastic waste (tonnes)` <int> NA, NA, NA, NA, NA, NA, NA...
## $ `Coastal population`                <int> NA, NA, NA, NA, NA, NA, NA...
## $ `Total population (Gapminder)`      <int> 3280000, 3280000, 4207000,...

用janitor package 清理变量名, 如 Mismanaged plastic waste (tonnes) 清理成了mismanaged_plastic_waste_tonnes

coast_vs_waste %>% clean_names() %>%glimpse()
## Observations: 20,093
## Variables: 6
## $ entity                          <chr> "Afghanistan", "Afghanistan", ...
## $ code                            <chr> "AFG", "AFG", "AFG", "AFG", "A...
## $ year                            <int> 1800, 1820, 1870, 1913, 1950, ...
## $ mismanaged_plastic_waste_tonnes <int> NA, NA, NA, NA, NA, NA, NA, NA...
## $ coastal_population              <int> NA, NA, NA, NA, NA, NA, NA, NA...
## $ total_population_gapminder      <int> 3280000, 3280000, 4207000, 573...
mismanaged_vs_gdp %>% clean_names() %>%glimpse()
## Observations: 22,204
## Variables: 6
## $ entity                                                           <chr> ...
## $ code                                                             <chr> ...
## $ year                                                             <int> ...
## $ per_capita_mismanaged_plastic_waste_kilograms_per_person_per_day <dbl> ...
## $ gdp_per_capita_ppp_constant_2011_international_rate              <dbl> ...
## $ total_population_gapminder                                       <int> ...
waste_vs_gdp %>% clean_names() %>%glimpse()
## Observations: 22,204
## Variables: 6
## $ entity                                                                     <chr> ...
## $ code                                                                       <chr> ...
## $ year                                                                       <int> ...
## $ per_capita_plastic_waste_kilograms_per_person_per_day                      <dbl> ...
## $ gdp_per_capita_ppp_constant_2011_international_constant_2011_international <dbl> ...
## $ total_population_gapminder                                                 <int> ...
coast_vs_waste2 = clean_names(coast_vs_waste) %>%filter(year>2000) %>% 
  group_by(year)%>%summarise(mismanaged_plastic_waste_tonnes=sum(mismanaged_plastic_waste_tonnes,na.rm = TRUE))

生成清理 function ‘clean_dataset’

clean_dataset <- function(tbl) {
  tbl %>%
    clean_names() %>%          # 清理变量名
    rename(country = entity,country_code = code) %>% # 改变量名
    filter(year == 2010) %>%   # 选2010年
    select(-year)              # 删除year变量
}
plastic_waste <- clean_dataset(coast_vs_waste) %>%  # 清洗数据 coast_vs_waste
  select(-total_population_gapminder) %>%           # 删除total_population_gapminder变量
  
  inner_join(clean_dataset(mismanaged_vs_gdp) %>%   # 清洗数据 mismanaged_vs_gdp
               select(-total_population_gapminder), # 删除total_population_gapminder变量
             by = c("country", "country_code")) %>% # inner join by "country", "country_code"
  
  inner_join(clean_dataset(waste_vs_gdp),           # 清洗数据 waste_vs_gdp
             by = c("country", "country_code")) %>% # inner join by "country", "country_code"
                                                    # 选变量
  select(country,
         country_code,
         mismanaged_waste = mismanaged_plastic_waste_tonnes,
         coastal_population,
         total_population = total_population_gapminder,
         mismanaged_per_capita = per_capita_mismanaged_plastic_waste_kilograms_per_person_per_day,
         plastic_waste_per_capita=per_capita_plastic_waste_kilograms_per_person_per_day,
         gdp_per_capita = gdp_per_capita_ppp_constant_2011_international_rate) %>%
  mutate(gdp_per_capita=round(gdp_per_capita))%>%
  
  filter(!is.na(mismanaged_waste),country!='Trinidad and Tobago')%>%                 # 选mismanaged_waste 非空的记录
   mutate(gdp_per_capita_group=cut_number(gdp_per_capita/1000, n = 4) # 按gdp_per_capita 排序 将国家分为 4组
          ,mismanaged_per_capita_rate=mismanaged_per_capita/plastic_waste_per_capita,
          managed_per_capita_rate=1-mismanaged_per_capita_rate
          
          )
glimpse(plastic_waste)
## Observations: 186
## Variables: 11
## $ country                    <chr> "Albania", "Algeria", "Angola", "An...
## $ country_code               <chr> "ALB", "DZA", "AGO", "AIA", "ATG", ...
## $ mismanaged_waste           <int> 29705, 520555, 62528, 52, 1253, 157...
## $ coastal_population         <int> 2530533, 16556580, 3790041, 14561, ...
## $ total_population           <int> 3204284, 35468208, 19081912, 15358,...
## $ mismanaged_per_capita      <dbl> 0.032, 0.086, 0.045, 0.010, 0.051, ...
## $ plastic_waste_per_capita   <dbl> 0.069, 0.144, 0.062, 0.252, 0.660, ...
## $ gdp_per_capita             <dbl> 9927, 12871, 5898, NA, 19213, 18712...
## $ gdp_per_capita_group       <fct> "(4.41,11.9]", "(11.9,28.7]", "(4.4...
## $ mismanaged_per_capita_rate <dbl> 0.46376812, 0.59722222, 0.72580645,...
## $ managed_per_capita_rate    <dbl> 0.5362319, 0.4027778, 0.2741935, 0....

作图

人类制造越来越多的垃圾 !

2010年每年制造近3亿万吨塑料垃圾.到2015年数字已上升到每年4亿万吨。这些垃圾不被回收的话将会污染我们的环境。

global_plastics_production%>%clean_names() %>%filter(year>2000) %>% 
ggplot(aes(x=year,y=global_plastics_production_million_tonnes_tonnes/1000000)) +geom_point()+geom_line()+

  labs(x = "年",
       y = "全球制造的塑料垃圾(百万吨)",
       #color = "Coastal population",
       title = "人类制造越来越多的垃圾",
       subtitle = "每年制造近4亿万吨塑料垃圾",
       caption ="统计时间:2000-2015年;数据源:ourworldindata.org
       @Tony Duan"
       )+theme(plot.title = element_text(hjust = 0.5))

Data weekend:Global Plastic Waste

谁制造垃圾 ?

人均收入越高的国家,制造的塑料垃圾越多。如美国人均每天制造0.3千克塑料垃圾。中国人均0.15千克。

g1 <- plastic_waste %>%
  arrange(-total_population) %>%
  mutate(pct_population_coastal = pmin(1, coastal_population / total_population),
         high_coastal_pop = ifelse(pct_population_coastal >= .8, ">=80%", "<80%")) %>%
  
  ggplot(aes(gdp_per_capita,plastic_waste_per_capita)) +
  
  geom_point(aes(size = total_population,fill = gdp_per_capita_group), shape = 21, show.legend = F, alpha = 0.7)+
  
  geom_text(aes(label = country), size=3,vjust = 1, hjust = 1, check_overlap = TRUE) +
  geom_smooth(method = "lm") +
  #scale_x_log10(labels = dollar_format()) +
  #scale_y_log10() +
  #scale_size_continuous(guide = FALSE) +
  labs(x = "人均GDP(美元)",
       y = "人均每天生成的塑料垃圾(千克)",
       #color = "Coastal population",
       title = "塑料垃圾与人口收入的关系",
       subtitle = "颜色为人均GPD组;点的大小代表国家总人口数量",
       caption ="统计时间:2010年;数据源:ourworldindata.org
       @Tony Duan"
       )+theme(plot.title = element_text(hjust = 0.5))

g1+ guides(fill=FALSE, color=FALSE)

Data weekend:Global Plastic Waste

谁回收垃圾 ?

人均收入越高的国家,垃圾回收率越高。如美国塑料垃圾回收率为90%。中国仅为25%。 可见人均收入最高的25%国家已建立有效的垃圾回收系统。所以垃圾回收能明显高于其他国家。

g2 <- plastic_waste %>%
  arrange(-total_population) %>%
  mutate(pct_population_coastal = pmin(1, coastal_population / total_population),
         high_coastal_pop = ifelse(pct_population_coastal >= .8, ">=80%", "<80%")) %>%
  
  ggplot(aes(gdp_per_capita, managed_per_capita_rate)) +
  
  geom_point(aes(size = total_population,fill = gdp_per_capita_group), shape = 21, show.legend = F, alpha = 0.7)+
  
  geom_text(aes(label = country), size=3,vjust = 1, hjust = 1, check_overlap = TRUE) +
  #geom_smooth(method = "lm") +
  scale_x_log10(labels = dollar_format()) +
  #scale_y_log10() +
  scale_size_continuous(guide = FALSE) +
  labs(x = "人均GDP(美元)",
       y = "塑料垃圾回收率",
       #color = "Coastal population",
       title = "塑料垃圾回收率与人口收入的关系",
       subtitle = "颜色为人均GPD组;点的大小代表国家总人口数量",
       caption ="统计时间:2010年;数据源:ourworldindata.org
       @Tony Duan"
       )+theme(plot.title = element_text(hjust = 0.5))

g2+ guides(fill=FALSE, color=FALSE)

Data weekend:Global Plastic Waste

结论

随着经济的发展。中国人均每天将生成越来越多垃圾。目前中国还处在较低的垃圾回收率。所以建立有效的垃圾回收系统迫在眉睫。上海市的垃圾分类立法将成为其他城市的学习榜样。


以上所述就是小编给大家介绍的《Data weekend:Global Plastic Waste》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

CSS 3实战

CSS 3实战

成林 / 机械工业出版社 / 2011-5 / 69.00元

全书一共分为9章,首先从宏观上介绍了CSS 3技术的最新发展现状、新特性,以及现有的主流浏览器对这些新特性的支持情况;然后详细讲解了CSS 3的选择器、文本特性、颜色特性、弹性布局、边框和背景特性、盒模型、UI设计、多列布局、圆角和阴影、渐变、变形、转换、动画、投影、开放字体、设备类型、语音样式等重要的理论知识,这部分内容是本书的基础和核心。不仅每个知识点都配有丰富的、精心设计的实战案例,而且详细......一起来看看 《CSS 3实战》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具