Как изобразить местоположение (долгота и высота) на карте в R? - PullRequest
0 голосов
/ 07 ноября 2018
devtools::install_github("dkahle/ggmap", ref = "tidyup")
library(ggmap)
chicago <- get_stamenmap(bbox = c(left = -88.0225, bottom = 41.5949, 
                              right = -87.2713, top = 42.0677), 
                     zoom = 11)

chicago_map <- ggmap(chicago) 

Теперь у меня есть карта Чикаго, у меня также есть данные о некоторых долготах и ​​высотах, я много раз пытался нанести эти местоположения на карту, не знаю, почему это не работает. Пожалуйста, посмотрите коды, которые я попробовал ниже:

ggplot(longitude_latitude.new, aes(x=Longitude, y=Latitude)) + 
     stat_density2d(aes(fill = ..level..), alpha=0.5, geom="polygon")+
     geom_point(colour="red")+
     geom_path(data=chicago_map,aes(x=long, y=lat,group=group), 
                colour="grey50")+
      scale_fill_gradientn(colours=rev(brewer.pal(7,"Spectral")))+
      coord_fixed()

Error: ggplot2 doesn't know how to deal with data of class gg/ggplot

Я также пытался получить карту с помощью Google API, но не работает ...

mymap <- get_map(location = longitude_latitude.new, source = "google",
             zoom = 14, maptype = "satellite")

Error in get_googlemap(center = location, zoom = zoom, maptype = maptype,  : 
Forbidden (HTTP 403).

Может кто-нибудь сказать мне, что делать дальше ... Я новичок в R и программировании, действительно сводит меня с ума ... Большое спасибо.

1 Ответ

0 голосов
/ 07 ноября 2018

У меня нет очков, которые вы используете, но попробуйте это.

devtools::install_github("dkahle/ggmap", ref = "tidyup")
library(ggmap)
chicago <- get_stamenmap(bbox = c(left = -88.0225, bottom = 41.5949, 
                                  right = -87.2713, top = 42.0677), 
                         zoom = 10)


longitude_latitude.new<- rbind(c( -87.6298,41.8781), c( -87.4298,41.9781))
longitude_latitude.new<-as.data.frame(longitude_latitude.new)
colnames(longitude_latitude.new) <- c('Longitude', 'Latitude')

chicago_map <- ggmap(chicago) 
chicago_map + geom_point(data = longitude_latitude.new, aes(x = Longitude , y = Latitude, size = 5))
...