Plot USA map - big white triangle. FIXED. New: geo

2019-08-06 12:17发布

问题:

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())


标签: r ggplot2 maps