slb95
slb95

Reputation: 23

Adding color to the ocean in R

I am mapping using the "oce" package in R and want to add color to the ocean. I can manipulate the land color but not the ocean, and the mapping function omits "bg" to add background color. Here is my current code and parameters:

library(oce)
library(ocedata)
data("coastlineWorldFine")
par(mar=c(2, 2, 1, 1))
lonlim <- c(-79, -76)
latlim <- c(33, 35)
mapPlot(coastlineWorldFine,
        projection="+proj=moll",
        col = "lightgray",
        longitudelim=lonlim,
        latitudelim=latlim,
        grid = FALSE,
        bg = "lightblue")

Any suggestions on how to change the color of the ocean from white to a light blue? Thanks!

Upvotes: 2

Views: 446

Answers (1)

Ian Campbell
Ian Campbell

Reputation: 24790

Bit of a hack, but you can plot a rectangle the same size as the plotting area, then use par(new = TRUE) to plot mapPlot on top:

par(mar=c(2, 2, 1, 1))
plot(0, 0, type="n", ann=FALSE, axes=FALSE)
user <- par("usr")
rect(user[1], user[3], user[2], user[4],
     col="lightblue", border=NA)
par(new = TRUE)
lonlim <- c(-79, -76)
latlim <- c(33, 35)
mapPlot(coastlineWorldFine,
         projection="+proj=moll",
         col = "lightgray",
         longitudelim=lonlim,
         latitudelim=latlim,
         grid = FALSE)

enter image description here

Upvotes: 1

Related Questions