Graticules are the longitude latitude lines shown on a projected map, and defining and drawing these lines is not easy to automate. The graticule package provides the tools to create and draw these lines by explicit specification by the user. This provides a good compromise between high-level automation and the flexibility to drive the low level details as needed, using base graphics in R.
You can install the released version of graticule from CRAN with:
And the development version from GitHub with:
# install.packages("devtools") devtools::install_github("mdsumner/graticule")
This is a basic example which shows how to create a graticule at specific longitude and latitude spacings and in a given projection.
There is an automatic segmentation that is done at equal distances along these rhumb lines. This is not an ideal spacing but is an improvement on the common alternatives, and is easier to work with when you need fine control.
If your projection is not wildly warped in most areas then the default rhumb line segmentation is the best first step.
This also allows the common case of creating a sensible single polygon wedge, i.e.
Give it a raster and let it plot, can provide
levels as per contour (values of longitude or latitude to draw as lines), and separate longitude or latitude plot on their own.
Sometimes it’s enough, sometimes we can muck around to get what we want.
tfile <- system.file("extdata", "nt_20140320_f17_v01_s.bin", package = "graticule", mustWork = TRUE) ice <- raster::raster(tfile) #> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj #> = prefer_proj): Discarded ellps unknown in Proj4 definition: +proj=stere #> +lat_0=-90 +lat_ts=-70 +lon_0=0 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m #> +no_defs +type=crs #> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = #> prefer_proj): Discarded datum unknown in Proj4 definition ice[!ice > 0] <- NA raster::plot(ice, col = palr::ice_pal(100)) lonlat(ice)
Please feel free to share your experiences and report problems at https://github.com/mdsumner/graticule/issues
graticule_labels()are created without using
xline/yline, need more careful separation between generating every combination in the grid versus single lines
Please note that the ‘graticule’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.