【问题标题】:R ggmap ggplot2 error "Error: Discrete value supplied to continuous scale"R ggmap ggplot2错误“错误:提供给连续比例的离散值”
【发布时间】:2015-11-09 05:39:34
【问题描述】:

首先,我很抱歉。

我知道有很多关于这个错误的帖子,但是我尝试了很多解决方案,但我没有设法解决我的问题。

我尝试将我的数据转换为多种形式,但仍然出现相同的错误,或者 ggplot2 不支持该数据格式。

这是我的代码:

library(ggmap)
library(ggplot2)
library(data.table)

setwd("~/Projects/reformat")
map <- get_map(location = c(-4,54.5), zoom = 6)
data <- read.csv('lonlatprice.csv')
colnames(data) <- c('Longitude','Latitude','Price')

ggmap(map, extent = "device") + geom_point(aes(x = data$Longitude, y = data$Latitude), colour = "red", 
                                                 alpha = 0.1, size = 2)

数据格式是这样的:

> head(data)
  Longitude   Latitude  Price
1 53.778274   -2.48129 147500
2 52.833819  -0.936527 182000
3 50.792457   0.046043 193000
4 51.476984  -0.612126 580000
5 51.460139   -0.01867 905000
6 52.235942   1.519404 641500

在此先感谢您的帮助,在无数天没有成功后,我只是作为最后的手段才提出的。

【问题讨论】:

  • 嗨,您可以链接到您查看过的问题,或者您尝试过但没有帮助的解决方案吗?这样我们就可以避免建议您已经浏览过的内容。

标签: r ggplot2 ggmap


【解决方案1】:

你的代码有几个问题:

  1. 您检索到了错误的地图。您混淆了get_map(location = c(-4,54.5), zoom = 6)lonlat 值的顺序
  2. 您以错误的方式调用geom_point 部分中的数据。

以下代码修复了这些问题:

map <- get_map(location = c(51.5,0.2), zoom = 6)

ggmap(map) + 
  geom_point(data= data,
             aes(x = Longitude, y = Latitude),
             colour = "red",
             alpha = 0.5,
             size = 4)

并给你这张地图:

【讨论】:

  • 啊,太棒了,谢谢!就我而言,这是一个愚蠢的错误。
猜你喜欢
  • 2018-06-20
  • 1970-01-01
  • 2014-11-14
  • 2014-05-27
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 2016-07-26
  • 2014-07-06
相关资源
最近更新 更多