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
5
votes
1 answer

R: ggplot2 with geom_map returns "x and units must have length > 0" error despite values converted to factors

I'm working on a primitive shiny app that would map some data from the Open Data for Scotland project. I worked out the SPARQL queries that manufacture a data frame resembling the extract provided below dz_label overall.quantiles S010001 8 S010002…
Konrad
  • 17,740
  • 16
  • 106
  • 167
5
votes
2 answers

Opening shapefiles in R using rgdal always better than using maptools?

I found two basic ways to open shapefiles in R - using rgdal and maptools: # 1 require(maptools) shape_maptools <- readShapeLines("file.shp") # 2 require(rgdal) shape_rgdal <- readOGR(".", "file") The data structures seem exactly the same in both…
Tomas
  • 57,621
  • 49
  • 238
  • 373
4
votes
1 answer

Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?

TL;DR What is the best way in R to handle SpatialPolygons intersecting/overlapping the anti meridian at +/-180° of latitude and cut them into two sections along that meridian? Preface This is going to be a long one, but only because I'm going to…
Where's my towel
  • 561
  • 2
  • 12
4
votes
1 answer

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

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…
BobbyF
  • 431
  • 1
  • 7
  • 19
4
votes
1 answer

Dissolving hexmap polygon shape files

I am trying to produce an outline for a hexagonal cartogram by dissolving the inner polygons via the unionSpatialPolygons or aggregate functions. I am getting stray hexs that do not dissolve... a dummy example to show the problem: # grab a dummy…
guyabel
  • 8,014
  • 6
  • 57
  • 86
4
votes
2 answers

Using a projection with xlim/ylim in R with the "maps" package results in a bigger map

I'm using R with the maps/mapproject/maptools packages to plot some maps and noticed a behavior which seems counter-intuitive to me and actually limits what I can do. Drawing a map of Europe (with the limits taken from the ETRS89 / ETRS-LCC, so…
fsmunoz
  • 75
  • 1
  • 5
4
votes
1 answer

Plotting small multiples with a for loop in R

I'm trying to plot a map small multiples grid that shows hurricanes/tropical storms that have intersected with Florida since 1900. I used some spatial queries to subset the database of all Atlantic storms for this project. I'm now plotting a line…
stiles
  • 56
  • 3
4
votes
1 answer

Read a shapefile with character encoding

Is there a way to read a shape file with a specific character encoding? I'm trying to read in a Canadian shapefile that has special (French) characters in some of the names. I can convert them manually, but I'd prefer not to do this if there's a…
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
4
votes
1 answer

get an empty SpatialPolygonsDataFrame via subset?

I'm looking to subset a SpatialPolygonsDataFrame by an attribute, but I want to allow it to return an empty SpatialPolygonsDataFrame. If we are to treat objects of type SpatialPolygonsDataFrame like data.frames, as discussed here, we should be able…
emudrak
  • 789
  • 8
  • 25
4
votes
4 answers

Opening SHP file in RStudio

I've a package of five files with all French administrative limits (available here). All these five files LIMITE_DEPARTEMENT.SHP/DBF/AVL/PRJ/SHX are in a the folder /home/jonathan/R. I use this code…
jonathan
  • 149
  • 4
  • 11
4
votes
1 answer

ggplot2 two data.frames, doesn't know how to deal with data of class uneval

I'm new to R and do not know how to plot two data.frames with ggplot2. I get the following error message: Error: ggplot2 doesn't know how to deal with data of class uneval How can I put together my data with the underlying world map? Here is my…
Til Hund
  • 1,543
  • 5
  • 21
  • 37
4
votes
1 answer

Convert SpatialLinesDataframe with multiple line elements to KML in R

I try to convert a spatial object (a river retrieved from OSM) with multiple lines to KML. For an object with a single line it is easy with kmlLine. However, with multiple lines the below approach is not working and my attempts to adapt the example…
Kay
  • 2,702
  • 6
  • 32
  • 48
3
votes
1 answer

snapPointsToLines can't keep attributes in R

I recently find a problem of snapPointsToLines. It can't keep the attributes of the spatial point dataframe. The example is as below: # Generate a spatial line dataframe l1 = cbind(c(1,2,3),c(3,2,2)) l1a = cbind(l1[,1]+.05,l1[,2]+.05) l2 =…
Freeego
  • 135
  • 6
3
votes
1 answer

Removing the Great Lakes from US county-level maps in R

I am using R to draw US map at county level. I downloaded the shapefile for US from GADM. The county-level shape file is "gadm36_USA_2.shp". I then used the code below to draw map: library(sf) library(tidyverse) us2 <-…
Patrick
  • 1,057
  • 9
  • 23
3
votes
1 answer

Simple world map with highlighted countries and selected cities

I would like to draw a world map and to highlight selected countries and cities. The countries and cities will present locations where study data were obtained. Unfortunately, I was able to do this. I could only highlight the countries. How could I…
Niels
  • 141
  • 12
1
2
3
10 11