Search code examples
rggplot2labelraster

Put label on a raster map according to latitude


library(raster)
dat <- getData('worldclim', var='tmin', res=10)
plot(dat$tmin1)

enter image description here

Is there a way to put labels on the above image depending on the latitude. For e.g latitude below -10 has one label, between -10 to 0 has another and so on. Something like below:

enter image description here


Solution

  • Plotting rasters is pretty much like any other base plotting. So you can modify the graphics just like for any other plot:

    # data
    library(raster)
    dat <- getData('worldclim', var='tmin', res=10)
    
    # define y locations for labels and lines
    
    y <- seq(-20,20,by = 10)
    
    # plot and suppress y axis (use axes=FALSE if you don't want either)
    
    plot(dat$tmin1,yaxt="n")
    
    # add labels 
    
    axis(2, at=y,labels=sprintf('%s deg. lat.',y), col.axis="darkgreen", las=2)
    
    # add lines
    
    abline(h=y,col='red',lty=2)
    

    enter image description here