Questions tagged [r-maptools]

The R package maptools provides a set of tools for manipulating and reading geographic data, in particular ESRI shapefiles.

The R package maptools is a set of tools for manipulating and reading data, in particular s. The package also provides interface wrappers for packages such as PBSmapping, spatstat, maps, RArcInfo, tmap, , , and others.

Repositories

Vignettes

Other resources

Related tags

157 questions
79
votes
5 answers

Simple way to subset SpatialPolygonsDataFrame (i.e. delete polygons) by attribute in R

I would like simply delete some polygons from a SpatialPolygonsDataFrame object based on corresponding attribute values in the @data data frame so that I can plot a simplified/subsetted shapefile. So far I haven't found a way to do this. For…
baha-kev
  • 3,029
  • 9
  • 33
  • 31
25
votes
3 answers

How to create a world map in R with specific countries filled in?

I would like to use R to generate a very basic world map with a specific set of countries filled with a red colour to indicate that they are malaria endemic countries. I have a list of these countries in a data frame but am struggling to overlay…
phlancelot
  • 281
  • 1
  • 4
  • 7
23
votes
2 answers

How to turn gpclibPermit() to TRUE

When I run gpclibPermit(), I've got the answer FALSE. How can I change it to be TRUE?
PAC
  • 5,178
  • 8
  • 38
  • 62
19
votes
7 answers

Error opening SHP file in R using maptools readShapePoly

I am new to R and was following the following tutorial on the ggplot2 package found here. However the readShapePoly() function throws an error whenever I try to load the basic shapefile. I have used the following…
Steve Senior
  • 191
  • 1
  • 1
  • 6
15
votes
2 answers

Converting a "map" object to a "SpatialPolygon" object

I am guessing there is a simple solution to the problem I have been having, but I am having some trouble. I am trying to convert the following map object: require(maps) usa <- map("state") into a SpatialPolygon object using the map2SpatialPolygons…
Mike.Gahan
  • 4,565
  • 23
  • 39
12
votes
1 answer

Plotting a raster behind a shapefile

How can I plot a "raster" object behind a shapefile object? Both plot fine on their own but the points don't plot over the raster: require(rgdal) require(maptools) require(raster) myproj = "+proj=utm +zone=12 +north +ellps=WGS84 +units=m" shp =…
Benjamin
  • 11,560
  • 13
  • 70
  • 119
10
votes
2 answers

How to tell what method is being used by a function call when `methods` fails?

Might as well let the cat out of the bag and say that I have been trying for about a day to figure out what is happening when I call plot for an object of class SpatialPolygons*. My instinct is to look for plot.SpatialPolygonsDataFrame, the approach…
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
10
votes
2 answers

SpatialPolygonDataFrame plotting using ggplot

I have a shape file for the greater London area. I use the readShapePoly function from the maptools package to load it in R as a SpatialPolygonDataFrame . I want to the plot those polygons .. Which I have already done by using the basic of plot…
Moustafa Alzantot
  • 397
  • 1
  • 4
  • 16
9
votes
2 answers

Merging Polygons in Shape Files with Common Tag IDs: unionSpatialPolygons

I am trying to read from a shape file and merge the polygons with a common tag ID. library(rgdal) library(maptools) if (!require(gpclib)) install.packages("gpclib", type="source") gpclibPermit() usa <- readOGR(dsn = "./path_to_data/",…
Rotail
  • 1,025
  • 4
  • 19
  • 40
9
votes
1 answer

Converting spatial polygon to regular data frame without use of gpclib tools

I working with spatial data in R for a commercial application and would like to use ggplot2 for data visualization. If you run the Hadley's example at https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles you find that in order to run…
aaron
  • 6,339
  • 12
  • 54
  • 80
7
votes
2 answers

R: count days that start at sunset

I'm analysing temporal patterns in a complex data set consisting of several environmental variables as well as activity data from various animal species. These data have been collected by multiple experimental setups, and data from each setup have…
Yuri Robbers
  • 291
  • 1
  • 10
6
votes
3 answers

How to add a scale bar in ggplot map

I have a simple map like this: library(maps) library(ggplot2) rs=map("world", col="gray80", xlim=c(32.002755, 44.283487), ylim=c(12.075434, 30.211327), resolution=0, bg="white", lty=1, lwd=2, fill=T) redsea=…
user5707371
  • 61
  • 1
  • 2
6
votes
1 answer

How to reduce white space margins of world map

library(maptools) data(wrld_simpl) plot(wrld_simpl) box() This gives me a world map and shows the plentiful white space top and bottom of the map. I would like this space to be gone as I need to print many (~60) maps. I am using knitr for the…
Gerit
  • 195
  • 2
  • 14
5
votes
1 answer

Plotting Thematic Maps in R Using Shapefiles and Data Files from DIfferent Sources

Given a shapefile, how do I shape and use a data file in order to be able to plot thematic maps using identifiers that correspond to shape regions in the shapefile? #Download English Government Office Network Regions (GOR)…
psychemedia
  • 5,690
  • 7
  • 52
  • 84
5
votes
2 answers

How to add Hawaii and Alaska to spatial polygons in R?

How can I add Hawaii and Alaska to the following code (taken from Josh O'Brien's answer here: Latitude Longitude Coordinates to State Code in R)? library(sp) library(maps) library(maptools) # The single argument to this function, pointsDF, is a…
Adam Smith
  • 2,584
  • 2
  • 20
  • 34
1
2 3
10 11