# Read earthquake dataset into R and map it with animation

#### masarimk

##### Member
Dear All,
I would like to read Turkey's eartquake data set into R and then plot with map with the animation according to the date(earlist to soonest
) that earthquake happened. Can you help me please?
Below is what I got so far but can't read the data.
Thank you.
Code:
install.packages('XML')
library(XML)
url <- "<http://www.koeri.boun.edu.tr/scripts/lst5.asp>"
data_df <- readHTMLTable(url)

#### helicon

##### Member
It isn't a table but fixed width data embedded in the page.

You can read it in using the following:

Code:
library(rvest)

widths <- c(11,10,10,10,14,5,5,5,48,100)

dat <- "http://www.koeri.boun.edu.tr/scripts/lst5.asp" %>%
html_nodes("pre") %>%
html_text %>%
textConnection %>%
read.fwf(widths = widths, stringsAsFactors = FALSE) %>%
setNames(nm = .[6,]) %>%
tail(-7) %>%
head(-2)

#### masarimk

##### Member
Thank you for your response jamesmartinn. I also would like to plot the map of the earthqakes happened. Below is what I got so far. But my question below:

Code:
#Loading necessary packages
library(rvest)
library(ggmap)
library(ggplot2)
library(dplyr)

widths <- c(11,10,10,10,14,5,5,5,48,100)
dat <- "http://www.koeri.boun.edu.tr/scripts/lst5.asp" %>%
html_nodes("pre") %>%
html_text %>%
textConnection %>%
read.fwf(widths = widths, stringsAsFactors = FALSE) %>%
setNames(nm = .[6,]) %>%
tail(-7) %>%

##converting to numeric vector
dat$"Boylam(E)" <- as.numeric(as.character(dat$"Boylam(E)"))
dat$"Enlem(N)" <- as.numeric(as.character(dat$"Enlem(N)"))
dat<- dat[, -c(3,4)]

dat$range = case_when(dat$ML>0 & dat$ML<=1 ~ 1, #0<ML<=1 dat$ML>1 & dat$ML<=2 ~ 2,#1<ML<=2 dat$ML>2 & dat$ML<=3 ~ 3,#2<ML<=3 dat$ML>3 & dat$ML<=4 ~ 4,#3<ML<=4 dat$ML>4 & dat$ML<=5 ~ 5,#4<ML<=5 dat$ML>5 & dat$ML<=6 ~ 6,#5<ML<=6 dat$ML>6 & dat\$ML<=7 ~ 7)#6<ML<=7

##first ploting Country
map <- get_map("Turkey", zoom = 5, maptype = "roadmap")
ggmap(map) +geom_point(data = dat,aes(x = "Boylam(E)", y ="Enlem(N)"),size = range ,alpha = .5)

Last edited:

#### masarimk

##### Member
Dear jamesmartinn,
When I run the top code, I got error message below. Can you help with that?
Thank you.
Code:
 ggmap(map) +geom_point(data = dat,aes(x = "Boylam(E)", y ="Enlem(N)"),size = range ,alpha = .5)
Error: Discrete value supplied to continuous scale
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.21527400612831116, "perplexity": 26102.79494529233}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-30/segments/1563195526254.26/warc/CC-MAIN-20190719140355-20190719162355-00074.warc.gz"}