library(readxl)
sumatera <- read_excel(path = "sumatera.xlsx")
sumatera
## # A tibble: 110 x 5
##    Pulau    Propinsi Tahun Inflow outflow
##    <chr>    <chr>    <dbl>  <dbl>   <dbl>
##  1 Sumatera Aceh      2011  2308.   6338.
##  2 Sumatera Aceh      2012  2620.   6378.
##  3 Sumatera Aceh      2013 36337.  23278.
##  4 Sumatera Aceh      2014  4567.   8630.
##  5 Sumatera Aceh      2015  4710.   9637.
##  6 Sumatera Aceh      2016  5775.  11311.
##  7 Sumatera Aceh      2017  5514.  11760.
##  8 Sumatera Aceh      2018  5799.  11450.
##  9 Sumatera Aceh      2019  7509.  13087.
## 10 Sumatera Aceh      2020  6641.  12874.
## # ... with 100 more rows
# Loading packages
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
sumatera %>% 
  ggplot(mapping = aes(x = Tahun, y = Inflow)) + 
  geom_point() + 
  facet_wrap(~ Propinsi)

# Loading packages
library(ggplot2)
library(dplyr)
   
sumatera %>% 
  ggplot(mapping = aes(x = Tahun, y = outflow)) +
  geom_line()+ 
  geom_point() + 
  facet_wrap(~ Propinsi)

aceh <-
  sumatera %>% 
  filter(Propinsi == "Aceh")
aceh %>% 
  ggplot(aes(Tahun, Inflow)) +
  geom_line() +
  geom_point() +
  geom_vline(xintercept = 2013, color = "blue")

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble  3.1.2     v purrr   0.3.4
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
tigasumatera <-
  sumatera %>% 
  filter(
    Propinsi %in% c("Aceh", "Bengkulu" ,"Jambi", "Lampung")
  ) %>% 
  filter(Tahun >= 2011, Tahun <= 2021)

tigasumatera %>% 
  mutate(Propinsi = fct_reorder2(Propinsi, Tahun, Inflow)) %>% 
  ggplot(aes(Tahun, Inflow, color = Propinsi)) +
  geom_vline(xintercept = 2016, color = "blue") +
  geom_line() +
  geom_point() +
  theme(legend.justification = "top") 

tigasumatera %>% 
  ggplot(aes(Tahun, Inflow, color = Propinsi)) +
  geom_vline(xintercept = 2016, color = "blue") +
  geom_line() +
  geom_point() +
  geom_text(
    aes(label = Propinsi),
    data = tigasumatera  %>% filter(Tahun == 2019),
    color = "black",
    hjust = 0,
    size = 3,
    nudge_x = 0.5
  ) +
  guides(color = "none") +
  coord_cartesian(xlim = c(2011, 2021)) 

sumatera %>% 
  mutate(Propinsi = fct_reorder(Propinsi, Inflow)) %>% 
  ggplot(aes(Propinsi, Inflow)) +
  geom_boxplot() + 
  geom_hline(aes(yintercept = median(Inflow, na.rm = TRUE)), color = "red")

sumatera %>% 
  mutate(Propinsi = fct_reorder(Propinsi, Inflow)) %>% 
  ggplot(aes(Propinsi, Inflow)) +
  geom_hline(aes(yintercept = median(Inflow, na.rm = TRUE)), color = "red") +
  geom_boxplot()+
  theme(axis.text.x = element_text(angle = -45))

library(tidyverse)
sumatera %>% 
  ggplot(aes(Inflow)) +
  geom_histogram() 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.