Rmaplibrary is intended to be a framework for geographic map plotting in R. It is designed to operate with map projections and multiple data formats.
Map projections are handled using the PROJ4 library.
Current supported data formats are:
Rmap_1.1.0.tar.gzfile. Extract it to a temporary directory with
tar zxvf Rmap_1.1.0.tar.gz- you can install R packages straight from tar files but you may need to edit some things at this stage of the package's development.
libproj.soor similar). If this is not in a system directory such as
/usr/local/lib/then you need to edit the
Makevarsfile in the
Rmap/srcdirectory before installing Rmap.
If you dont want Projection support, edit
-lproj from the
line. Actually, no, that wont work because the PROJ4 library symbols
will be undefined and the code wont load. Get and install PROJ4 - its
worth it. Again, make sure you build a shared PROJ4 library, so that you
libproj.so in a system directory.
If you really cant get PROJ4 built, then I think if you delete the
projectit.c file from the
src directory, and remove
-lproj from Makevars then you will build without PROJ4 support.
Make sure you build and install a shared library,
libshp.so or similar). If this is not in a system
directory such as
/usr/local/lib then you need to edit
Makevars before building and installing Rmap. Make
sure the path to the shapelib header file is specified too.
Makevarsfile and remove OGR support.
R CMD INSTALL Rmapor to install to a non-system directory, do:
R CMD INSTALL -l ~/MyRLibs/ Rmap- in the latter case you need to do:
library(Rmap,lib.loc="~/MyRLibs")to access it.
There is some code for reading Shapefiles that uses only R code for reading binary files, and since this needs no shapefile library it should work under Windows. If anyone wants to port this into Rmap then please do!
Rmaplibrary uses objects in R to access general geographical data sources. These data sources could be simple R objects, objects that access data files, or potentially objects that get their data from databases or servers.
As an example, we illustrate how to draw maps using an ESRI shapefile. This is a relatively simple data format, and widely used. Physically a shapefile consists of three actual system files:
file.shp- the geographic coordinates.
file.shx- some spatial indexing.
file.dbf- a DBase file of attributes.
This gives us our basic model for geographic data - a data frame with associated spatial objects. Many operations on data frames can also be used on geographic objects in Rmap.
euadmll.shp(it is fairly conventional to consider the
.shpfile and call it 'the shapefile' even though a
.dbffile are also involved). This is a map of regions in a large part of western Europe (obtained from the UNEP web site as an E00 file and converted to a shapefile using e002shp).
We create a new object with the
> euadmll <- shapefile("euadmll.shp") Warning message: Invalid names in DBF file, new names are: EUADMLL# is now EUADMLL. EUADMLL-ID is now EUADMLL.IDFirst note that some of the names in the DBF file were not good expressions for R column names, and so were renamed. We can check this with the
> names(euadmll)  "AREA" "PERIMETER" "EUADMLL." "EUADMLL.ID" "ARRGCD"  "NURGCD" "ARRGCTCD" "ARRGLBLV" "TOTAREA" "POP80"  "POP85" "POP87" "POP88" "POP89" "POP90"  "POP91"If we print this object out we get a message:
> euadmll its a shapefile the file is /home/rowlings/Geog/Shapelib/Rshape/inst/samples/euadmll.shp its dimension is 2556 rows by 16 columnsWe can access data using
$NAMEas with a data frame:
> euadmll$AREA[25:28]  0.012 21.600 0.210 0.024Note that the precision of the result is limited to whatever precision was specified in the DBF file when it was created.
> euadmll[1:10,] its a shapefile the file is /home/rowlings/Geog/Shapelib/Rshape/inst/samples/euadmll.shp its dimension is 10 rows by 16 columnsIf you want to get the data itself, then convert the object to a data frame:
> as.data.frame(euadmll[5:10,1:5]) AREA PERIMETER EUADMLL# EUADMLL-ID ARRGCD 1 0.201 7.162 5 6 NO03 2 0.087 1.55 6 7 NO03 3 0.003 0.261 7 5 NO03 4 0.138 3.51 8 8 NO03 5 0.057 1.828 9 10 NO03 6 0.006 0.387 10 11 NO16
> plot(euadmll) > plot(euadmll[grep("^UK",euadmll$ARRGCD),])By default this will use the most appropriate type of map according to the data set - such as points, lines or polygons. You can get the type with the
You can also use
to add to an existing plot.
proj=function to apply a map projection. The argument is a character string that is passed to the PROJ4 library - see the documentation for PROJ4 for full details - here is an example of a plot using a Mercator projection:
> plot(euadmll,proj="+proj=merc")Once a plot has been started using a projection, further plots should use the same projection parameter.
The underlying function for projecting coordinates is
xy is a 2-column
matrix of coordinates and
proj is a string for the PROJ4
inv parameter controls whether the forward
or inverse transform is used. Passing
inv=T causes the
inverse transform to be used (if available for that projection) so
that coordinates on the plot device can be converted back to
save.image()early and often.