1
votes

I read earthquake data from website. I tried to graph it by using getmap but I received an error mesagge that I can't solve.

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

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

##converting to numeric vector
dat$"Boylam(E)" <- as.numeric(as.character(dat$"Boylam(E)"))
dat$"Enlem(N)" <- as.numeric(as.character(dat$"Enlem(N)"))

#I removed duplicates.
dat<- dat[, -c(3,4)]

##adding range to ML
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)

My error message:

Error: Discrete value supplied to continuous scale

1

1 Answers

1
votes

Replace x = "variable.name" with x = `variable.name`. The ggplot2 package (like other packages in tidyverse) use non-standard evaluation (NSE), so it usually accepts variable names in its functions without ". For variable names such as Boylam(E), which may be interpreted as functions, surround them with backticks ` instead.

ggmap(map) + 
  geom_point(data = dat,
             aes(x = `Boylam(E)`, y = `Enlem(N)`, size = range), 
             alpha = .5)

Also, I assume you intended for size = range to be inside aes()?

plot