How can I color the ocean blue in a map of the US?

I would like to draw a map of the US over an image, but then fill in the oceans.

here is my starting point:

image(x=-90:-75, y = 25:40, z = outer(1:15, 1:15, "+"), 
      xlab = "lon", ylab = "lat")
map("state", add = TRUE)

But I would like the Atlantic Ocean and Gulf of Mexico to be filled in a solid color.


Good question! How's this?

image(x=-90:-75, y = 25:40, z = outer(1:15, 1:15, "+"), 
      xlab = "lon", ylab = "lat")
map("state", add = TRUE)

outline <- map("usa", plot=FALSE) # returns a list of x/y coords
xrange <- range(outline$x, na.rm=TRUE) # get bounding box
yrange <- range(outline$y, na.rm=TRUE)
xbox <- xrange + c(-2, 2)
ybox <- yrange + c(-2, 2)
# create the grid path in the current device
polypath(c(outline$x, NA, c(xbox, rev(xbox))),
         c(outline$y, NA, rep(ybox, each=2)),
         col="light blue", rule="evenodd")

I came across the solution to this problem after reading Paul Murrell's (the man behind grid) recent R-Journal article on grid paths (pdf here).


"It’s Not What You Draw, It’s What You Don’t Draw" -Paul Murrell (R Journal Vol. 4/2)

Need Your Help

Make an event where that detects if a boolean becomes true to display a message

python qt pyside

I have a GUI application that works with printers connected via USB. What I've got now is the code to detect whenever a printer was connected to the computer. But what I'm trying to achieve is a si...

What are the difference between pom.xml and effective pom in Apache Maven?


Could somebody explain to me, what are are differences between the file pom.xml and the file effective pom.xml in an apache maven project?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.