Skip to content

Instantly share code, notes, and snippets.

@jurand71
Created July 19, 2022 11:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jurand71/9726a5949cc3a33cea8111aa1eb484cc to your computer and use it in GitHub Desktop.
library(tidyverse)
library(scales)
#sciezka do danych
setwd('F:/R/Dane/Odpady')
#pobranie danych z GUS - ilosc zebranych (wytworzonych) odpadow
odpady <- read.csv2('odpady_wojewodztwa_rok.csv', sep =";", stringsAsFactors = F, encoding="UTF-8")
#usuniecie niepotrzebnych kolumn
odpady <- odpady[,c(1,2,4:11)]
odpady <- na.omit(odpady)
# kod TERYT województwa jest dwucyfrowy dwie pierwsze cyfry
odpady$Kod <- ifelse(nchar(odpady$Kod) == 6, paste0("0",odpady$Kod), odpady$Kod)
odpady$Kod <- substr(odpady$Kod, 1, 2)
# laczna ilosc zebranych odpadów
odpady %>%
group_by(Rok) %>%
summarise(
Wartosc = sum(Zebrane)
) %>%
filter(Rok %in% 2016:2021) %>%
ggplot(aes( x = Rok, y = Wartosc)) +
geom_line() +
geom_point(color="red", size=3) +
geom_text(aes(label = Wartosc), vjust = - 0.85) +
scale_x_continuous(breaks = c(seq(2016, 2021, by = 1))) +
scale_y_continuous(breaks = pretty_breaks(n = 6), limits = c(11000,14000)) +
labs(title = "Ilość zebranych odpadów komunalnych (2016-2021)",
subtitle = "Źródło danych: Baza danych lokalnych GUS",
x="", y="tys. ton") +
theme_minimal()
# laczna ilosc selektywnie zebranych odpadów
odpady %>%
group_by(Rok) %>%
summarise(
Wartosc = sum(Selektywnie)
) %>%
ungroup() %>%
filter(Rok %in% 2016:2021) %>%
ggplot(aes( x = Rok, y = Wartosc)) +
geom_line() +
geom_point(color="red", size=3) +
geom_text(aes(label = Wartosc), vjust = - 0.85) +
scale_x_continuous(breaks = c(seq(2016, 2021, by = 1))) +
# scale_y_continuous(breaks = pretty_breaks(n = 6), limits = c(11000,14000)) +
labs(title = "Ilość selektywnie zebranych odpadów komunalnych (2016-2021)",
subtitle = "Źródło danych: Baza danych lokalnych GUS",
x="", y="tys. ton") +
theme_minimal()
# na jednym wykresie
odpady %>%
group_by(Rok) %>%
summarise(
Zebrane = sum(Zebrane),
Selektywnie = sum(Selektywnie),
PMTS = sum(PMTS)
) %>%
ungroup() %>%
filter(Rok %in% 2016:2021) %>%
mutate(Procent = Selektywnie/Zebrane*100) %>%
ggplot() +
geom_bar(mapping = aes(x = Rok, y = Procent*120), stat = "identity", fill = "grey", alpha = 0.5) +
geom_text(mapping = aes(x = Rok, y = Procent*120, label = paste0(round(Procent, 2),"%")),vjust=3.5) +
geom_line(mapping = aes(x = Rok, y = Zebrane)) +
geom_point(mapping = aes(x = Rok, y = Zebrane),color="red", size=3) +
geom_text(mapping = aes(x = Rok, y = Zebrane, label = paste0(round(Zebrane, 2))),vjust = 2.0) +
geom_line(mapping = aes(x = Rok, y = Selektywnie)) +
geom_point(mapping = aes(x = Rok, y = Selektywnie),color="blue", size=3) +
geom_text(mapping = aes(x = Rok, y = Selektywnie, label = paste0(round(Selektywnie, 2))),vjust = -1.0) +
geom_line(mapping = aes(x = Rok, y = PMTS)) +
geom_point(mapping = aes(x = Rok, y = PMTS),color="yellow", size=3) +
geom_text(mapping = aes(x = Rok, y = PMTS, label = paste0(round(PMTS, 2))),vjust = 2.0) +
scale_y_continuous(name = "tys. ton",
sec.axis = sec_axis(~./120,name = "%")) +
labs(title = "Ilość odpadów komunalnych zebranych ogółem, selektywne, PMTS (2016-2021)",
subtitle = "Źródło danych: Baza danych lokalnych GUS", x="") +
theme_minimal()
tail(odpady,20)
# na jednym wykresie wojewodztwo
odpady %>%
filter(Nazwa == "ZACHODNIOPOMORSKIE", Rok %in% 2016:2021) %>%
mutate(Zmieszane = Zebrane - Selektywnie,
Procent = Selektywnie/Zebrane*100) %>%
ggplot() +
geom_bar(mapping = aes(x = Rok, y = Procent*6.5), stat = "identity", fill = "grey", alpha = 0.5) +
geom_text(mapping = aes(x = Rok, y = Procent*6.5, label = paste0(round(Procent, 2),"%")), vjust=4.5) +
geom_line(mapping = aes(x = Rok, y = Zebrane)) +
geom_point(mapping = aes(x = Rok, y = Zebrane),color="red", size=3) +
geom_text(mapping = aes(x = Rok, y = Zebrane, label = paste0(round(Zebrane, 2))),vjust = 2.0) +
geom_line(mapping = aes(x = Rok, y = Selektywnie)) +
geom_point(mapping = aes(x = Rok, y = Selektywnie),color="blue", size=3) +
geom_text(mapping = aes(x = Rok, y = Selektywnie, label = paste0(round(Selektywnie, 2))),vjust = -1.0) +
geom_line(mapping = aes(x = Rok, y = Zmieszane)) +
geom_point(mapping = aes(x = Rok, y = Zmieszane),color="yellow", size=3) +
geom_text(mapping = aes(x = Rok, y = Zmieszane, label = paste0(round(Zmieszane, 2))),vjust = 2.0) +
scale_y_continuous(name = "tys. ton",
sec.axis = sec_axis(~./6.5,name = "%")) +
labs(title = "Ilość odpadów komunalnych zebranych w woj. zachodniopomorskim:\nogółem, resztkowe, selektywne (2016-2021)",
subtitle = "Źródło danych: Baza danych lokalnych GUS", x="") +
theme_minimal()
odpady %>%
filter(Rok %in% 2016:2021) %>%
ggplot(aes(Rok, Zebrane)) +
geom_line() +
geom_point(color="red", size=2) +
facet_wrap(~Nazwa, scales = "free_y") +
scale_x_continuous(breaks = c(seq(2016, 2021, by = 1))) +
labs(title = "Ilość zebranych odpadów komunalnych w poszczególnych województwach (2016-2021)",
subtitle = "Źródło danych: Baza danych lokalnych GUS",
x="", y="tys. ton") +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment