Last active
April 4, 2018 21:31
-
-
Save oscarperpinan/5d5bb51ff419621d5f63429b8f88d679 to your computer and use it in GitHub Desktop.
Revisions
-
oscarperpinan revised this gist
Apr 4, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ library(raster) library(rgdal) library(rasterVis) library(graticule) -
oscarperpinan revised this gist
Apr 4, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ r <- getRaster('temp', day = testDay, frames = 1) ## Here is where the graticule routine starts crs.longlat <- CRS("+init=epsg:4326") prj <- CRS(projection(r)) extLL <- projectExtent(r, crs = crs.longlat) lons <- pretty(c(xmin(extLL), xmax(extLL))) lats <- pretty(c(ymin(extLL), ymax(extLL))) -
oscarperpinan created this gist
Apr 9, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ library(rasterVis) library(graticule) ## Only needed for downloading a raster example library(meteoForecast) today <- Sys.Date() testDay <- today - 7 ## Retrieve raster data r <- getRaster('temp', day = testDay, frames = 1) ## Here is where the graticule routine starts crs.longlat <- CRS("+init=epsg:4326") prj <- CRS(projection(r)) extLL <- projectExtent(r, crs.longlat) lons <- pretty(c(xmin(extLL), xmax(extLL))) lats <- pretty(c(ymin(extLL), ymax(extLL))) ## optionally, specify the extents of the meridians and parallels ## here we push them out a little on each side xl <- range(lons) + c(-0.4, 0.4) yl <- range(lats) + c(-0.4, 0.4) ## build the lines with our precise locations and ranges grat <- graticule(lons, lats, proj = prj, xlim = xl, ylim = yl) ## Labels labs <- graticule_labels(lons, lats, xline = lons[2], yline = lats[2], proj = prj) labsLon <- labs[labs$islon,] labsLat <- labs[!labs$islon,] ## Display the raster levelplot(r) + ## and the graticule layer(sp.lines(grat)) + layer(sp.text(coordinates(labsLon), txt = parse(text = labsLon$lab), adj = c(1.1, -0.25), cex = 0.6)) + layer(sp.text(coordinates(labsLat), txt = parse(text = labsLat$lab), adj = c(-0.25, -0.25), cex = 0.6))