ggmap

plot small region of a large polygon map in ggplot2

北城余情 提交于 2020-02-17 06:35:07
问题 I have a shapefile which I fortified and plotted in ggplot2 using geom_polygon . How can I plot only a small region of this map? My full map looks fine, but my small region is messed up. Here is a working example: This small shapefile can be obtained from: http://www.mappinghacks.com/data/TM_WORLD_BORDERS_SIMPL-0.2.zip #read data spf<-readOGR(getwd(),"TM_WORLD_BORDERS_SIMPL-0.2") spf@data$id<-rownames(spf@data) #fortify spf1<-fortify(spf,region="id") #full plot ggplot(spf1)+geom_polygon(aes

plot small region of a large polygon map in ggplot2

冷暖自知 提交于 2020-02-17 06:34:13
问题 I have a shapefile which I fortified and plotted in ggplot2 using geom_polygon . How can I plot only a small region of this map? My full map looks fine, but my small region is messed up. Here is a working example: This small shapefile can be obtained from: http://www.mappinghacks.com/data/TM_WORLD_BORDERS_SIMPL-0.2.zip #read data spf<-readOGR(getwd(),"TM_WORLD_BORDERS_SIMPL-0.2") spf@data$id<-rownames(spf@data) #fortify spf1<-fortify(spf,region="id") #full plot ggplot(spf1)+geom_polygon(aes

Plotting both state AND county boundaries on same map using plot_usmap from usmap package in R

ぃ、小莉子 提交于 2020-02-06 07:56:12
问题 I would like to create a map of the US showing both state and county boundaries (i.e. state boundaries in a different color). I typically do this using either shape files that I import or using ggplot2 's map_data function. However, I face three obstacles. 1) I cannot install gdal and geos in my computing environment so that precludes the use of any shape files or GeoJSON files (my attempts to map county level shape files loaded using fastshp have not been successful but I'm open to any

Plotting both state AND county boundaries on same map using plot_usmap from usmap package in R

China☆狼群 提交于 2020-02-06 07:56:07
问题 I would like to create a map of the US showing both state and county boundaries (i.e. state boundaries in a different color). I typically do this using either shape files that I import or using ggplot2 's map_data function. However, I face three obstacles. 1) I cannot install gdal and geos in my computing environment so that precludes the use of any shape files or GeoJSON files (my attempts to map county level shape files loaded using fastshp have not been successful but I'm open to any

Error: (list) object cannot be coerced to type 'integer'

橙三吉。 提交于 2020-02-02 12:52:48
问题 I am getting this error in R when I try to run the function route() within a loop: Error: (list) object cannot be coerced to type 'integer' The function is found in the package "ggmap". It takes two strings as an argument and searches on google maps the directions between them. It returns a dataframe which contains information about the route including distance, minutes, coordinates etc. I have a vector with many strings which represent postcodes and I am using this route() function within a

Size variable in ggmap's get_googlemap no longer seems to work

ぃ、小莉子 提交于 2020-01-25 09:35:07
问题 The following function returns a plot of noise in the current version of ggmap (3.0.0): library(ggmap) register_google(key = "my_key") ggmap(get_googlemap(size = c(620, 640))) The plot appears correctly, however, when a square of any pixel dimensions is used (i.e., 640x640, 500x500, etc.). It's also worth noting that the URL returned by get_googlemap when using non-square dimensions is valid when pasted into the web browser, so the issue seems to be in how ggmap parses and plots the URL. I've

Trouble reading in geojson/json file into R for plotting on map

半腔热情 提交于 2020-01-23 11:35:48
问题 I'm trying to read in a json file which contains polylines into R for plotting in leaflet or ggmap. The file is in the geojson format. The file can be found at: http://datasets.antwerpen.be/v4/gis/statistischesector.json I've tried: library(rgdal) library(jsonlite) library(leaflet) geojson <- readLines("statistischesector.json", warn = FALSE) %>% paste(collapse = "\n") %>% fromJSON(simplifyVector = FALSE) This actually reads in the file but it seems to be in a wrong format for further

Plotting GPS coordinates using ggmap

懵懂的女人 提交于 2020-01-15 06:53:28
问题 I am attempting to create a plot of gps coordinates on a map in R using ggmap. Here is the first 10 rows of the dataset I am using: gps[1:10,] X_id lon timestamp lat 1 5555bcda65bc7d0f2c8d1a9c -4.018623 2015-05-15T09:31:06.859Z 53.23945 2 5555bcdb65bc7d0f2c8d1a9f -4.018623 2015-05-15T09:31:07.371Z 53.23945 3 5555bcdb65bc7d0f2c8d1aa2 -4.018623 2015-05-15T09:31:07.868Z 53.23945 4 5555bcdc65bc7d0f2c8d1aa5 -4.018623 2015-05-15T09:31:08.364Z 53.23945 5 5555bcdc65bc7d0f2c8d1aa8 -4.018623 2015-05

US border line is not added to geom_map maps of dispersed US regions

眉间皱痕 提交于 2020-01-14 12:49:07
问题 I have a map of dispersed parts in the Us. This is in the following question (that contains link to the data): mapping by ggplot2 geom_polygon goes crazy after merging data It was answered very well. Then I tried to add the US border line, therefore I added the geom_path to the answered code,but no result, it creates the same map just containing the dispersed areas. library(ggplot2) #library(tidyverse) library(dplyr) library(maps) load("./data.rda") usa <- map_data("usa") shape_map <- tbl_df

US border line is not added to geom_map maps of dispersed US regions

[亡魂溺海] 提交于 2020-01-14 12:47:09
问题 I have a map of dispersed parts in the Us. This is in the following question (that contains link to the data): mapping by ggplot2 geom_polygon goes crazy after merging data It was answered very well. Then I tried to add the US border line, therefore I added the geom_path to the answered code,but no result, it creates the same map just containing the dispersed areas. library(ggplot2) #library(tidyverse) library(dplyr) library(maps) load("./data.rda") usa <- map_data("usa") shape_map <- tbl_df