【问题标题】:Error: Discrete value supplied to continuous scale ggmap错误:提供给连续比例 ggmap 的离散值
【发布时间】:2018-05-11 08:26:44
【问题描述】:

我从网站上读取地震数据。我尝试使用 getmap 对其进行绘图,但收到一条我无法解决的错误消息。

# 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)

我的错误信息:

错误:提供给连续刻度的离散值

【问题讨论】:

    标签: r ggmap


    【解决方案1】:

    x = "variable.name" 替换为x = `variable.name`。 ggplot2 包(与 tidyverse 中的其他包一样)使用非标准评估 (NSE),因此它通常在其函数中接受不带 " 的变量名称。对于变量名,例如 Boylam(E),可能会被解释为函数,而是用反引号 ` 将它们括起来。

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

    另外,我假设您打算将 size = range 放在 aes() 内部?

    【讨论】:

    • 非常感谢 Z.Lin,但不幸的是,当我从互联网上读取数据时,你能告诉我 Boylam(E),Enlem(N) 读取字符螺母数字。我该如何解决?谢谢。
    猜你喜欢
    • 2015-11-09
    • 2018-06-20
    • 2014-11-14
    • 2023-03-06
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 2019-12-18
    • 2015-01-08
    相关资源
    最近更新 更多