Learn R Programming

mapmisc (version 1.2.1)

scaleBar: Map with scale bar

Description

Utilities for plotting a map, adding a scale bar and north arrow, and adding a legend of colour scales.

Usage

scaleBar(crs, pos = "bottomright", scale.cex = 1, outer=TRUE,...)
map.new(x,legendRight=FALSE)
insetMap(crs, pos="bottomright",map="osm",zoom=0, 
		width=0.2, col="#FF000090", borderSmall=NA, borderBig=NULL,
			cropInset = extent(-180,xmax=180, ymin=-47, ymax=71),
			outer=TRUE)

Arguments

crs
A CRS object, proj4 string, or an object from which a projection can be extracted with proj4string(crs)
pos
Position, as specified in the legend function.
scale.cex
Scaling factor for the scale bar.
x
A spatial object from which an extent can be extracted.
legendRight
Leave room to the right for the legend produced by plotting a Raster object
map
Either a Raster for the inset map or a string passed to openmap's path argument
zoom
Zoom level if retreiving inset map from openmap
width
Width of the inset map, as a fraction of the plot window
col
Colour for shaded region of inset map
borderSmall,borderBig
border style for the inset map and shaded region, passed as the bg argument to polygon
cropInset
Crop the insert map to this extent
outer
If TRUE, put bar or map in the margin of the plot
...
breaks = c(-100, -1, 1, Inf) thecol = c('red','orange','blue')

Additional arguments passed to legend, for examaple bty='n'

Details

scaleBar produces a scale bar reflecting the distance travelling on a great circle from the centre of the plot and travelling to the right. The length of the bar is the width of 6 characters times scale.cex.

map.new initiates a plot intended to contain a map covering the extent of x, with no margins.

See Also

scalebar, spplot

Examples

Run this code
Npoints = 20
myPoints = SpatialPointsDataFrame(
	cbind(runif(Npoints), 51+runif(Npoints)), 
	data=data.frame(y1=c(NA, rnorm(Npoints-1)), 
	y2=c(sample(0:5, Npoints-1,replace=TRUE), NA)),
	proj4string=CRS(
	"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
	)
)

mymap = openmap(myPoints)

breaks = c(-100, -1, 1, Inf)
thecol = c('red','orange','blue')


map.new(myPoints)
plot(mymap,add=TRUE)
plot(myPoints,col = as.character(cut(
	myPoints$y1, breaks, thecol
)),add=TRUE)
scaleBar(myPoints, "bottomright",cex=1.25, scale.cex=2)
temp=legendBreaks("topleft", legend=breaks, col=thecol)

insetMap(myPoints, "bottomleft",col='blue')

Run the code above in your browser using DataLab