Hey,
I am trying to create a open street map of Hanoi and add data points from my data frame to it. But I'm always getting the same error no matter what I try. I found a similar post from someone with the same error and they solved by adding "+scale_fill_continuous(guide=FALSE)" , that doesn't help me however.
My code:
library(OpenStreetMap)
library(ggmap)
library(osmdata)
library(ggplot2)
library(tidyverse)
library(rgdal)
traps <- data.frame(name=c("Kim Ma","An Khanh","Gia Quat", "Ngoc Ha", "Cu Khoi N", "Cu Khoi S"),
longitude=c(105.818147,105.732711,105.879748,105.8265118,105.9067497,105.9067648),
latitude=c(21.031584,21.008828,21.055393,21.0399774,21.0083294,21.0081745))
location=c(106,20.5,105.6,21.1)
Fetch the map
Hanoi = get_map(location = location, source = "osm", zoom = 3)
Draw the map
Hanoimap = ggmap(Hanoi)
Add the points layer
Hanoimap = Hanoimap + geom_point(data=traps, aes(x = longitude, y = latitude), size = 5)
Add the labels
Hanoimap + geom_text(data=traps,mapping=aes(x = longitude+.001, y = latitude,label = name))
The error:
rror in grid.Call.graphics(C_raster, x$raster, x$x, x$y, x$width, x$height, : Empty raster
-
grid.Call.graphics(C_raster, x$raster, x$x, x$y, x$width, x$height, resolveHJust(x$just, x$hjust), resolveVJust(x$just, x$vjust), x$interpolate)
-
drawDetails.rastergrob(x, recording = FALSE)
-
drawDetails(x, recording = FALSE)
-
drawGrob(x)
-
recordGraphics(drawGrob(x), list(x = x), getNamespace("grid"))
-
grid.draw.grob(x$children[[i]], recording = FALSE)
-
grid.draw(x$children[[i]], recording = FALSE)
-
drawGTree(x)
-
recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
-
grid.draw.gTree(x$children[[i]], recording = FALSE)
-
grid.draw(x$children[[i]], recording = FALSE)
-
drawGTree(x)
-
recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
-
grid.draw.gTree(gtable)
-
grid.draw(gtable)
-
print.ggplot(x)
-
(function (x, ...) UseMethod("print"))(x)
Thank you for your help!
/Janina