根据纬度和经度设置ggmap边界

时间:2015-07-02 15:09:08

标签: r google-maps latitude-longitude ggmap

所以我有R程序,我正在努力获得地图中的所有点

 DELIMITER $$

 CREATE TRIGGER trg_reviews_after_insert 
 AFTER INSERT ON reviews
 FOR EACH ROW
 BEGIN
    INSERT INTO productsmaster (col1, col2, userid, usergender, userage, score)
    SELECT p.col1
         , p.col2
         , NEW.userid
         , NEW.usergender
         , NEW.userage
         , NEW.score
      FROM products p
      WHERE p.pid = NEW.pid;
  END$$

 DELIMITER $$

这是输出地图

enter image description here

我希望在不删除数据点的情况下放大,但无论我在地图上选择哪个位置,数据都会被切断,即library(ggmap) library(ggplot2) setwd("d:/GIS/") sep <- read.csv("SEP_assets_csv.csv") Sub1 <- sep[grep("SEP.12", names(sep))] sep$newCol <- 100*rowSums(Sub1)/rowSums(sep[4:7]) # create a new grouping variable Percent_SEP12_Assets <- ifelse(sep[,8] >= 50, "Over 50", "Under 50") # get the map map <- get_map("Kissena Park, Queens", zoom = 13, maptype = 'roadmap') # plot the map and use the grouping variable for the fill inside the aes ggmap(map) + geom_point(data=sep, aes(x = Longitude, y = Latitude, color=Percent_SEP12_Assets ), size=9, alpha=0.6) + scale_color_manual(breaks=c("Over 50", "Under 50"), values=c("green","red"))

有没有办法根据纬度和经度的极值设置边界?我在

导入的csv
Removed 2 rows containing missing values (geom_point).

有纬度和经度列表。

帮助!

坐标

sep <- read.csv("SEP_assets_csv.csv")

dput

Latitude    Longitude
40.758365   -73.824407
40.774168   -73.818543
40.761748   -73.811379
40.765602   -73.828293
40.751762   -73.81778
40.764834   -73.789712
40.777951   -73.842932
40.76501    -73.794319
40.785959   -73.817349
40.755764   -73.799256
40.745593   -73.829283
40.789929   -73.839501
40.760072   -73.783908
40.726437   -73.807592
40.741093   -73.808757
40.720926   -73.823358
40.729642   -73.81781
40.724191   -73.80937
40.782346   -73.77844
40.778164   -73.799841
40.775122   -73.8185
40.760344   -73.817909
40.792326   -73.809516
40.78322    -73.806977
40.73106    -73.805449
40.736521   -73.813001
40.783714   -73.795027
40.770194   -73.82762
40.735855   -73.823583
40.74943    -73.82141
40.769753   -73.832001
40.754465   -73.826204
40.738775   -73.823892
40.764868   -73.826819
40.738332   -73.82028
40.735017   -73.821339
40.72535    -73.811325
40.721466   -73.820401

1 个答案:

答案 0 :(得分:4)

您尚未向我们提供任何数据,因此我将使用historydata包中的数据集给出一个示例。您可以根据数据集中纬度和经度的边界框获取地图,而不是根据位置和缩放获取地图。

library(historydata)
library(ggmap)
data("catholic_dioceses")

bbox <- make_bbox(catholic_dioceses$long, catholic_dioceses$lat, f = 0.01)
map <- get_map(bbox)

ggmap(map) +
  geom_point(data=catholic_dioceses, aes(x = long, y = lat))

请注意,f =的{​​{1}}参数可让您控制地图周围的填充量。

在你的情况下,我认为这将有效:

make_bbox()