Plot USA map - big white triangle. FIXED. New: geocode limit of 2500 requests per day

徘徊边缘 提交于 2019-12-13 01:13:49

问题


When plotting map of USA, I get the map but with a big white triangle in the middle. Anyone sees the same?

require(ggplot2)
require(ggmap)
require(maps)

US <- map_data("usa", region=".")

plot(ggplot(US, aes(x=long, y=lat)) +
       geom_polygon() +
       coord_map())

The above problem is fixed. Now I wan to mark cities on map with number of ads/calls/etc - a data frame of 4900 locations. However, google restricts usage to non-business users to 2500 per day. Do you know of a more elegant solution other than breaking the DF in smaller (<= 2500) rows data frames, making a geopoint, and stitching?

E.g. like that, with pseudodata:

state = rep("IL", 2500)
city  = rep("Chicago", 2500)
ads   = rep(15, 2500)


ads_df = data.frame(state,city,ads)
ads_df <- cbind(geocode(as.character(ads_df$city)), ads_df)

state= rep("FL", 2500)
city  = rep("Miami", 2500)
ads   = rep(15, 2500)

ads_df1 = data.frame(state,city,ads)
ads_df1 <- cbind(geocode(as.character(ads_df1$city)), ads_df1)

ads_df = rbind(ads_df,ads_df1)

plot(ggplot(US, aes(x=long, y=lat)) +
              geom_polygon(aes(group = group) ) +
              coord_map() + geom_point(data=ads_df, aes(x=lon, y=lat, size=ads), color="orange"))

回答1:


ggmaps is set up to use group for polygons:

> plot(ggplot(US, aes(x=long, y=lat)) +
+          geom_polygon(aes(group = group)) +
+          coord_map())


来源:https://stackoverflow.com/questions/29041196/plot-usa-map-big-white-triangle-fixed-new-geocode-limit-of-2500-requests-pe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!