[R-sig-Geo] multi-map figure

Christopher Lusk clusk at waikato.ac.nz
Mon Oct 5 03:31:15 CEST 2015


Hi - I want to combine 3 maps in one figure, showing geographic patterns of
species richness. Looks OK with the script below, but as the axes are the
same on all 3 maps, I've been trying to remove the space between the 3
panels, and get rid of y-axis ticks and tick labels on panels (b) and (c)
as well. But neither of these is happening, despite several approaches. Can
anyone see what I need to change? Any advice would be appreciated. The data
can be downloaded here:

http://sci.waikato.ac.nz/sites/clusk/DivrepNZ.csv
....................

library(maps)
library(mapdata)

par(mfrow = c(1, 3))
par(mar = c(0, 0, 0, 0), oma = c(1, 1.5, 0.5, 0.5))

map("worldHires","New Zealand", xlim=c(166,179),ylim=c(-48,-34),lty=1,
col="gray", fill=FALSE)
title(xlab = NULL, ylab="Latitude (degrees S)", cex.lab=1.2)
map.axes(cex.axis=0.85, las=1)
DivrepNZ <- read.csv("DivrepNZ.csv")
z <- DivrepNZ$Nativearborescent
zcol <- colorRampPalette(c('greenyellow', 'green4',
'black'))(100)[as.numeric(cut(z, breaks = 100))]
points(DivrepNZ$lon, DivrepNZ$lat, pch = 15, cex = 0.45, col = zcol)
box()
text(178,-35, "(a)", cex=1.2)
xleft <- 167
xright <- 168
ybot <- -39
yint <- (39 - 35) / 100
ytop <- ybot + yint
for(c in colorRampPalette(c('greenyellow', 'green4', 'black'))(100))
{ybot = ybot + yint
  ytop = ytop + yint
  rect(xleft, ybot, xright, ytop, border = NA, col = c)
  print(c(xleft, xright, ybot, ytop, c))
}
labels <- round(seq(min(z), max(z), length.out = 5),2)
text(c(xright + 0.2),
     seq(-39, -35, length.out = 5),
     labels = as.character(labels),
     cex = 0.85,
     pos = 4)
text(178, -35, "(a)")

map("worldHires","New Zealand", xlim=c(166,179),ylim=c(-48,-34),lty=1,
col="gray", fill=FALSE, yaxt=NULL)
title(xlab = "Longitude (degrees E)", ylab=NULL, cex.lab=1.2)
map.axes(cex.axis=0.85, las=1)
DivrepNZ <- read.csv("DivrepNZ.csv")
z <- DivrepNZ$Divaricates
zcol <- colorRampPalette(c('orange', 'orangered4',
'black'))(100)[as.numeric(cut(z, breaks = 100))]
points(DivrepNZ$lon, DivrepNZ$lat, pch = 15, cex = 0.45, col = zcol)
box()
text(178,-35, "(b)", cex=1.2)
xleft <- 167
xright <- 168
ybot <- -39
yint <- (39 - 35) / 100
ytop <- ybot + yint
for(c in colorRampPalette(c('orange', 'orangered4', 'black'))(100))
{ybot = ybot + yint
  ytop = ytop + yint
  rect(xleft, ybot, xright, ytop, border = NA, col = c)
  print(c(xleft, xright, ybot, ytop, c))
}
labels <- round(seq(min(z), max(z), length.out = 5),2)
text(c(xright + 0.2),
     seq(-39, -35, length.out = 5),
     labels = as.character(labels),
     cex = 0.85,
     pos = 4)
text(178, -35, "(b)")

map("worldHires","New Zealand", xlim=c(166,179),ylim=c(-48,-34),lty=1,
col="gray", fill=FALSE, yaxt=NULL)
Show axes with horizontal tick labels
map.axes(cex.axis=0.85, las=1)
title(xlab = NULL, ylab=NULL, cex.lab=1.2)
DivrepNZ <- read.csv("DivrepNZ.csv")
z <- DivrepNZ$divrep
zcol <- colorRampPalette(c('lightskyblue', 'deepskyblue4',
'black'))(100)[as.numeric(cut(z, breaks = 100))]
points(DivrepNZ$lon, DivrepNZ$lat, pch = 15, cex = 0.45, col = zcol)
box()
text(178,-35, "(c)", cex=1.2)
xleft <- 167
xright <- 168
ybot <- -39
yint <- (39 - 35) / 100
ytop <- ybot + yint
for(c in colorRampPalette(c('lightskyblue', 'deepskyblue4', 'black'))(100))
{ybot = ybot + yint
  ytop = ytop + yint
  rect(xleft, ybot, xright, ytop, border = NA, col = c)
  print(c(xleft, xright, ybot, ytop, c))
}
labels <- round(seq(min(z), max(z), length.out = 6),2)
text(c(xright + 0.2),
     seq(-39, -35, length.out = 6),
     labels = as.character(labels),
     cex = 0.85,
     pos = 4)
text(178, -35, "(c)")


--
Dr. Chris Lusk
Environmental Research Institute
The University of Waikato
Private Bag 3105, Hamilton
New Zealand / Aotearoa
http://sci.waikato.ac.nz/sites/clusk/
Ph 64 7 838 4205
~  ~  ~  ~  ~  ~  ~

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list