library(DataExplorer)
library(dplyr)
library(ggmap)
library(ggplot2)
library(lubridate)
library(sp)
library(tidyverse)earthquake <- read.csv("deprem.csv")
head(earthquake,10)## id date time lat long country city City
## 1 2.00e+13 20.05.2003 12:17:44 ÖÖ 39.04 40.38 turkey Bingol Bingol
## 2 2.01e+13 1.08.2007 12:03:08 ÖÖ 40.79 30.09 turkey Kocaeli Kocaeli
## 3 1.98e+13 7.05.1978 12:41:37 ÖÖ 38.58 27.61 turkey manisa Manisa
## 4 2.00e+13 22.03.1997 12:31:45 ÖÖ 39.47 36.44 turkey sivas Sivas
## 5 2.00e+13 2.04.2000 12:57:38 ÖÖ 40.80 30.24 turkey sakarya Sakarya
## 6 2.01e+13 21.01.2005 12:04:03 ÖÖ 37.11 27.75 turkey mugla Mugla
## 7 2.01e+13 24.06.2012 12:07:22 ÖÖ 38.75 43.61 turkey van Van
## 8 1.99e+13 31.12.1987 12:49:54 ÖÖ 39.43 27.98 turkey balikesir Balikesir
## 9 2.00e+13 7.02.2000 12:11:45 ÖÖ 40.05 34.07 turkey kirikkale Kirikkale
## 10 2.01e+13 28.10.2011 12:47:56 ÖÖ 38.76 43.54 turkey van Van
## area direction dist depth xm md richter mw ms mb
## 1 baliklicay west 0.1 10.0 4.1 4.1 0.0 NA 0 0.0
## 2 bayraktar_izmit west 0.1 5.2 4.0 3.8 4.0 NA 0 0.0
## 3 hamzabeyli south_west 0.1 0.0 3.7 0.0 0.0 NA 0 3.7
## 4 kahvepinar_sarkisla south_west 0.1 10.0 3.5 3.5 0.0 NA 0 0.0
## 5 meseli_serdivan south_west 0.1 7.0 4.3 4.3 0.0 NA 0 0.0
## 6 demirciler_milas south_west 0.1 32.8 3.5 3.5 0.0 NA 0 0.0
## 7 ilikaynak south_west 0.1 9.4 4.5 0.0 4.5 NA 0 0.0
## 8 dikkonak_bigadic south_east 0.1 26.0 3.8 3.8 0.0 NA 0 0.0
## 9 kocabas_delice south_east 0.1 1.0 3.8 3.8 0.0 NA 0 0.0
## 10 degirmenozu south_east 0.1 3.1 4.3 0.0 4.2 NA 0 4.3
# "jitter" sayilari yuvarlama isleminin onune gecer.
earthquake$lat <- jitter(earthquake$lat)
earthquake$long <- jitter(earthquake$long)
earthquake$xm <- jitter(earthquake$xm)
head(earthquake)## id date time lat long country city
## 1 2.00e+13 20.05.2003 12:17:44 ÖÖ 39.03907 40.37992 turkey Bingol
## 2 2.01e+13 1.08.2007 12:03:08 ÖÖ 40.78918 30.08918 turkey Kocaeli
## 3 1.98e+13 7.05.1978 12:41:37 ÖÖ 38.58104 27.60993 turkey manisa
## 4 2.00e+13 22.03.1997 12:31:45 ÖÖ 39.47111 36.43941 turkey sivas
## 5 2.00e+13 2.04.2000 12:57:38 ÖÖ 40.79822 30.23821 turkey sakarya
## 6 2.01e+13 21.01.2005 12:04:03 ÖÖ 37.11118 27.74874 turkey mugla
## City area direction dist depth xm md richter
## 1 Bingol baliklicay west 0.1 10.0 4.090730 4.1 0
## 2 Kocaeli bayraktar_izmit west 0.1 5.2 3.988104 3.8 4
## 3 Manisa hamzabeyli south_west 0.1 0.0 3.682027 0.0 0
## 4 Sivas kahvepinar_sarkisla south_west 0.1 10.0 3.486467 3.5 0
## 5 Sakarya meseli_serdivan south_west 0.1 7.0 4.311548 4.3 0
## 6 Mugla demirciler_milas south_west 0.1 32.8 3.515945 3.5 0
## mw ms mb
## 1 NA 0 0.0
## 2 NA 0 0.0
## 3 NA 0 3.7
## 4 NA 0 0.0
## 5 NA 0 0.0
## 6 NA 0 0.0
earthquake <- earthquake %>%
mutate(date = dmy(date))library(tidyverse)
unique(earthquake$country)## [1] turkey azerbaijan bulgaria mediterranean
## [5] greece georgia russia iran
## [9] macedonia aegeansea syria blacksea
## [13] cyprus_greek cyprus_turkish iraq romania
## [17] turkiye_iran turkiye_armenia turkiye_syria turkiye_iraq
## [21] israel #NAME? albania ukrainia
## [25] turkiye_georgia egypt
## 26 Levels: #NAME? aegeansea albania azerbaijan blacksea ... ukrainia
ulke_shiny <- earthquake %>%
filter(country == "turkey") %>%
summarise(mean = mean(xm),
frekans = nrow(earthquake %>% filter(country == "turkey")))turkey <- earthquake %>%
filter(country == "turkey") plot_missing(turkey)"mw" değişkenimin büyük kısmı NA değere sahip olduğu için ve kullanmayacağım için 15. degişkenim olan mw yi veri setimden kaldırıyorum.
turkey <- turkey[ ,-16]
turkey <- na.omit(turkey) Turkiye verisinin dagilimini gorsel olarak incelemek icin histogram, boxplot gibi grafikleri kullanabiliriz.
hist(turkey$xm, main = "xm - HISTOGRAM", xlab = "Deprem Siddeti", col = "grey", border = "black") xm degerlerine ait histogramda 10 grup vardir.Turkiye merkezli depremlerin normal dagilmadigini soyleyebiliriz. Histograma baktigimiz zaman saga carpik bir dagilim gormekteyiz. Verimizin buyuk cogunlugunu 3,4 araligindaki depremler olusturmaktadir. Histograma bakarak basit bir yorum yapmak istersek Turkiyedeki buyuk siddetli depremlerin frekansinin cok fazla oldugu soylenemez.
boxplot(turkey$xm, main = "xm - BOXPLOT", ylab = "Deprem Siddeti", col = "grey", border = "black") Box plota baktigimizda ise xm degeri 5 in uzerinde olan depremlerin outliers olarak yer aldigini gormekteyiz. Outlier degerler dagilimdaki aykiri degerleri ifade etmektedir. Yani box plota bakarakta turkiyedeki depremlerin genellikle kucuk siddetli depremler oldugunu soyleyebiliriz.
Turkiyede buyuk siddetli depremlerin cok fazla gozlemlenmedigini dagilimlara bakark yorumlamistik. Peki bu outlier degerler hangi sehirlerde ve hangi yillarda gerceklesmis ?
top <- turkey %>%
group_by(date) %>%
arrange(desc(xm))
top_10 <- head(top,10)
top_10## # A tibble: 10 x 17
## # Groups: date [10]
## id date time lat long country city City area direction
## <dbl> <date> <fct> <dbl> <dbl> <fct> <fct> <fct> <fct> <fct>
## 1 1.94e13 1939-12-26 12:5~ 39.8 39.5 turkey erzi~ Erzi~ kuru~ north_ea~
## 2 1.98e13 1976-11-24 12:2~ 39.1 44.0 turkey van Van yeni~ south_ea~
## 3 2.00e13 1999-08-17 12:0~ 40.8 30.0 turkey Koca~ Koca~ basi~ north_ea~
## 4 1.91e13 1912-08-09 12:2~ 40.6 27.2 turkey teki~ Teki~ erik~ south_ea~
## 5 1.95e13 1953-03-18 12:0~ 40.0 27.4 turkey cana~ Cana~ sogu~ south_we~
## 6 1.94e13 1943-11-26 12:2~ 41.0 33.7 turkey cank~ Cank~ come~ north_we~
## 7 2.01e13 2011-10-23 12:4~ 38.7 43.4 turkey van Van yeml~ north_we~
## 8 1.94e13 1944-02-01 12:2~ 41.4 32.7 turkey kara~ Kara~ ince~ north_we~
## 9 2.00e13 1999-11-12 12:5~ 40.7 31.2 turkey duzce Duzce ugur north_ea~
## 10 1.96e13 1957-05-26 12:3~ 40.7 31.0 turkey duzce Duzce guze~ south_we~
## # ... with 7 more variables: dist <dbl>, depth <dbl>, xm <dbl>, md <dbl>,
## # richter <dbl>, ms <dbl>, mb <dbl>
plot(top_10$xm, ylab = "xm", xlab = "TOP10", main = "EN SIDDETLI 10 DEPREM", type = "o", lwd = 2, pch = 16, col = "black") # "text" fonksiyonu ile grafikteki noktalari adlandirdim.
text(x=1.7, y=7.9, labels = "Erzincan - 1939", adj = 1, cex = 0.75)
text(x=2.51, y=7.51, labels = "Van - 1976", adj = 1, cex = 0.75)
text(x=3.7, y=7.4, labels = "Kocaeli - 1999", adj = 1, cex = 0.75)
text(x=4.8, y=7.3, labels = "Tekirdag - 1912", adj = 1, cex = 0.75)
text(x=5.6, y=7.22, labels = "Duzce - 1999", adj = 1, cex = 0.75)
text(x=6.5, y=7.22, labels = "Van - 2011", adj = 1, cex = 0.75)
text(x=7.6, y=7.22, labels = "Cankiri - 1943", adj = 1, cex = 0.75)
text(x=8.7, y=7.22, labels = "Canakkale - 1953", adj = 1, cex = 0.75)
text(x=9.6, y=7.22, labels = "Karabuk - 1944", adj = 1, cex = 0.75)
text(x=9.9, y=7.1, labels = "Tokat - 1916", adj = 1, cex = 0.75)Turkiyede gerceklesen en siddetli 10 depremi top_10 olarak atadim ve bu degerlerin daha iyi incelenebilmesi icin verileri gorsellestirdim. Grafige baktigimizda ılkemizdeki en siddetli depremin 1939 yilinda Erzincan'da gerceklestigini gormekteyiz. En siddetli depremlerden en yakin tarihte gozlemlenen deprem ise 2011 yilinda Van ilimizde gerceklesmistir.
min <- turkey %>%
group_by(country) %>%
arrange(xm)
head(min)## # A tibble: 6 x 17
## # Groups: country [1]
## id date time lat long country city City area direction
## <dbl> <date> <fct> <dbl> <dbl> <fct> <fct> <fct> <fct> <fct>
## 1 2.01e13 2006-05-21 12:5~ 38.2 42.9 turkey van Van yani~ south_we~
## 2 2.00e13 1997-03-01 12:3~ 40.8 35.4 turkey amas~ Amas~ kire~ east
## 3 2.01e13 2005-10-05 12:4~ 38.0 27.9 turkey aydin Aydin yuka~ north
## 4 2.00e13 1999-09-16 12:3~ 40.6 30.7 turkey saka~ Saka~ guzl~ east
## 5 1.99e13 1991-07-11 12:4~ 39.0 29.8 turkey kuta~ Kuta~ sara~ south_ea~
## 6 2.01e13 2007-05-16 12:4~ 39.9 39.3 turkey gumu~ Gumu~ yesi~ south_we~
## # ... with 7 more variables: dist <dbl>, depth <dbl>, xm <dbl>, md <dbl>,
## # richter <dbl>, ms <dbl>, mb <dbl>
tur <- readRDS("gadm36_TUR_1_sp (1).rds")
map_data <- tur@data
head(map_data)## GID_0 NAME_0 GID_1 NAME_1 VARNAME_1 NL_NAME_1 TYPE_1 ENGTYPE_1
## 1 TUR Turkey TUR.1_1 Adana Seyhan <NA> Il Province
## 12 TUR Turkey TUR.2_1 Adiyaman Adıyaman <NA> Il Province
## 23 TUR Turkey TUR.3_1 Afyon Afyonkarahisar <NA> Il Province
## 34 TUR Turkey TUR.4_1 Agri Ağri|Karaköse <NA> Il Province
## 45 TUR Turkey TUR.5_1 Aksaray <NA> <NA> Il Province
## 56 TUR Turkey TUR.6_1 Amasya <NA> <NA> Il Province
## CC_1 HASC_1
## 1 <NA> TR.AA
## 12 <NA> TR.AD
## 23 <NA> TR.AF
## 34 <NA> TR.AG
## 45 <NA> TR.AK
## 56 <NA> TR.AM
harita_data <- turkey %>%
group_by(city) %>%
summarise(mean = mean(xm),
lat = mean(lat),
long = mean(long))
head(harita_data)## # A tibble: 6 x 4
## city mean lat long
## <fct> <dbl> <dbl> <dbl>
## 1 adana 3.94 37.2 35.6
## 2 adiyaman 4.03 37.8 38.4
## 3 afyonkarahisar 3.95 38.5 30.6
## 4 agri 4.11 39.6 43.5
## 5 aksaray 3.97 38.3 33.8
## 6 amasya 3.90 40.7 35.5
"harita_data" daki "city" degiskeni ile "map_data" daki "sehirler" uyusmadigi icin "harita_data"daki city degiskenini kaldirdim ve yerine yeni bir city degiskeni atadim.
harita_data <- harita_data[ ,-1]
city <- data.frame(sehir = c("Adana","Adiyaman","Afyon","Agri","Aksaray","Amasya","Ankara","Antalya","Ardahan","Artvin","Aydin","Balikesir","Bartin","Batman","Bayburt","Bilecik","Bingol","Bitlis","Bolu","Burdur","Bursa","挼㸷anakkale","挼㸷ankiri","挼㸷orum","Denizli","Diyarbakir","D昼㹣zce","Edirne","Elaz昼㹤昼㸰","Erzincan","Erzurum","Eskisehir","Gaziantep","Giresun","G昼㹣m昼㹣shane","Hakkari","Hatay","I昼㸰d昼㹤r","Isparta","Istanbul","Izmir","K.Maras","Karab昼㹣k","Karaman","Kars","Kastamonu","Kayseri","Kilis","Kinkkale","Kirklareli","Kirsehir","Kocaeli","Konya","K昼㹣tahya","Malatya","Manisa","Mardin","Mersin","Mugla","Mus","Nevsehir","Nigde","Ordu","Osmaniye","Rize","Sakarya","Samsun","Sanliurfa","Siirt","Sinop","Sirnak","Sivas","Tekirdag","Tokat","Trabzon","Tunceli","Usak","Van","Yalova","Yozgat","Zinguldak"))
harita_data <- cbind(city, harita_data)
head(harita_data, 10)## sehir mean lat long
## 1 Adana 3.938486 37.21791 35.64107
## 2 Adiyaman 4.032692 37.82764 38.35934
## 3 Afyon 3.945297 38.46275 30.60081
## 4 Agri 4.105272 39.56543 43.53361
## 5 Aksaray 3.969937 38.33777 33.82968
## 6 Amasya 3.904866 40.71461 35.49715
## 7 Ankara 3.835794 39.70590 32.92808
## 8 Antalya 3.907130 36.87017 30.58052
## 9 Ardahan 4.288303 41.47553 42.88422
## 10 Artvin 4.152689 41.07482 42.06652
tur <- readRDS("gadm36_TUR_1_sp (1).rds")
plot(tur)tur@data <- tur@data %>%
as_tibble()
# Datay昼㹤 tibble dosyas昼㹤 haline getirdik, b昼㸶ylece ilerleyen a昼㹥amalarda tidyverse i攼㸷erisinde yer alan tidyr k昼㹣t昼㹣phanesindeki left_join komutunun kullan昼㹤m昼㹤n昼㹤 kolayla昼㹥t昼㹤rd昼㹤k.
head(tur@data)## # A tibble: 6 x 10
## GID_0 NAME_0 GID_1 NAME_1 VARNAME_1 NL_NAME_1 TYPE_1 ENGTYPE_1 CC_1
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 TUR Turkey TUR.~ Adana Seyhan <NA> Il Province <NA>
## 2 TUR Turkey TUR.~ Adiya~ Adıyaman <NA> Il Province <NA>
## 3 TUR Turkey TUR.~ Afyon Afyonkar~ <NA> Il Province <NA>
## 4 TUR Turkey TUR.~ Agri AÄŸri|Kar~ <NA> Il Province <NA>
## 5 TUR Turkey TUR.~ Aksar~ <NA> <NA> Il Province <NA>
## 6 TUR Turkey TUR.~ Amasya <NA> <NA> Il Province <NA>
## # ... with 1 more variable: HASC_1 <chr>
tur_for <- fortify(tur) # Bu fonksiyon 'sp' paketinin i攼㸷inde.## Regions defined for each Polygons
id_and_cities<- data_frame(id = rownames(tur@data), sehir = tur@data$NAME_1) %>%
left_join(harita_data, by = "sehir")## Warning: `data_frame()` is deprecated, use `tibble()`.
## This warning is displayed once per session.
## Warning: Column `sehir` joining character vector and factor, coercing into
## character vector
head(id_and_cities)## # A tibble: 6 x 5
## id sehir mean lat long
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 1 Adana 3.94 37.2 35.6
## 2 2 Adiyaman 4.03 37.8 38.4
## 3 3 Afyon 3.95 38.5 30.6
## 4 4 Agri 4.11 39.6 43.5
## 5 5 Aksaray 3.97 38.3 33.8
## 6 6 Amasya 3.90 40.7 35.5
final_map <- left_join(tur_for, id_and_cities, by = "id")ggplot(final_map) +geom_polygon( aes(x = long.x, y = lat.x, group = group, fill = mean), color = "grey") +
coord_map() +theme_void() + labs(title = "ORTALAMA DEPREM DAæ¼ã¸°ILIMI")+
scale_fill_distiller(name = "Deprem Siddeti",palette = "Spectral", limits = c(3.7,4.375
), na.value = "white") +
theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5))"Ortalama Deprem Dağılımı" olarak adlandirdigim grafik sayesinde Turkiye haritasi uzerinde sehirlerde gerceklesen depremlerin ortalama siddetini goruyoruz. Bu gorsel ile ortalama deprem siddetlerini goruyoruz. Peki ulkemizde gerceklesen her bir depremi harita uzerinde nokta nokta gosterebilirmiyiz ?
turkiye_dagilim<- turkey %>%
filter(lat<=42.01000) %>%
filter(long<=44.13992) # Veri icerisindeki aykiri kordinat degerlerini filtreledim.
ggplot(final_map) +
geom_polygon( aes(x = long.x, y = lat.x, group = group),fill = "white",color = "black") +
coord_map() +theme_void() + labs(title = "TURKIYE MERKEZLI DEPREMLER")+
scale_color_distiller(name = "Deprem Siddeti",palette = "Spectral", limits = c(3.5,8))+
theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5))+
geom_point( data = turkiye_dagilim,aes(x=long, y = lat,col = xm), alpha = 0.9999)+
labs(x='long', y='lat', fill='xm')# geom_point( data = turkiye_dagilim,aes(x=long, y = lat,col = xm, alpha = xm))+
# geom_point fonksiyonu icindeki alpha argumanini xm yapilirsa grafikteki her nokta deprem siddetine gore daha opak olacaktir. "TURKIYE MERKEZLI DEPREMLER" grafigine baktigimizda ise Turkiye sinirlari icerisinde gerceklesen 9882 farkli depremin ulkedeki dagilimini gorebiliyoruz.
ulkeler <- earthquake %>%
group_by(country) %>%
summarise(ortalama = mean(xm))
ulkeler <- ulkeler[-20:-26, ]
ulkeler <- ulkeler[-14:-17, ]
ulkeler <- ulkeler[-7:-9, ]
ulkeler <- ulkeler[-5, ]
ulkeler <- ulkeler[-1:-3, ]
# Her bir ulkede gerceklesen ortalama deprem siddetini ulkeler olarak atadim ve bu veri icindeki komsu ulke olmayan gozlemleri verimden cikardim.
a1 <- ggplot(data = ulkeler, aes(x = country, y = ortalama , col = ortalama))+
geom_point()+
theme(axis.text.x = element_text(angle = -90))
ggplot(data = ulkeler, aes(x = country, y = ortalama , col = ortalama))+
geom_point()+
theme(axis.text.x = element_text(angle = -90))ulkeler_frekans <- earthquake %>%
group_by(country) %>%
count(country)
ulkeler_frekans <- ulkeler_frekans[-20:-26, ]
ulkeler_frekans <- ulkeler_frekans[-14:-17, ]
ulkeler_frekans <- ulkeler_frekans[-7:-9, ]
ulkeler_frekans <- ulkeler_frekans[-5, ]
ulkeler_frekans <- ulkeler_frekans[-1:-3, ]
a2 <- ggplot(data = ulkeler_frekans, aes(x = country, y = n , col = n))+
geom_point()+
theme(axis.text.x = element_text(angle = -90))
ggplot(data = ulkeler_frekans, aes(x = country, y = n , col = n))+
geom_point()+
theme(axis.text.x = element_text(angle = -90))