Dannygem
Dannygem

Reputation: 31

R ggmap ggplot2 error "Error: Discrete value supplied to continuous scale"

first of all, I apologise.

I know there is numerous threads about this error, however I have tried numerous solutions and I have not managed to get any to solve my issue.

I have tried transforming my data into numerous forms but I still get the same error, or that ggplot2 does not support that data format.

Here is my code:

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)

This is what the data format is like:

> 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

Thanks in advance for help, I have only asked as a last resort after numerous days of no success.

Upvotes: 1

Views: 4068

Answers (1)

Jaap
Jaap

Reputation: 83215

There are several problems with your code:

  1. You retrieved the wrong map. You mixed up the order of the lon and lat values in get_map(location = c(-4,54.5), zoom = 6)
  2. You are calling the data in the geom_point part in the wrong way.

The following code fixes these problems:

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)

and gives you this map:

enter image description here

Upvotes: 3

Related Questions