I have the following code in R
mp1 <- fortify(map(fill=TRUE, plot=FALSE))
mp2 <- mp1
mp2$long <- mp2$long + 360
mp2$group <- mp2$group + max(mp2$group) + 1
mp <- rbind(mp1, mp2)
map <- (ggplot(aes(x = long, y = lat, group = group), data = mp) +
geom_path() +
scale_x_continuous(name="Longitude",minor_breaks=seq(170,246,2), limits = c(170, 246)) +
scale_y_continuous(name= "Latitude",minor_breaks=seq(30,64,2),limits = c(30, 64)))
which produces this image
My aim next is to colour in the 'pixels' (or breaks) blue depending on whether they are land or not (I'm showing which parts of the map I have a times series for to put the task into context) so I run this for loop which shades in the relevant pixels I have data to get this image
Is there a way to get the original plot lines (so the breaks going up at 170,172,..... and across at 30,32,.....) and also the original map so that it goes over to filled in blue bits.
The for loop I used was:
for(i in 1:663){
if(sst.yearly.matrix[i,3] != sst.yearly.matrix[1,3]){
map <- map + annotate("rect", xmin=sst.yearly.matrix[i,2], xmax=sst.yearly.matrix[i,2]+2,
ymin=sst.yearly.matrix[i,1],ymax=sst.yearly.matrix[i,1]+2, fill="deepskyblue")
}
}
Any help is much appreciated! Thanks.