0

I want to draw shaded area with dots for example inside my spatial plot in R. I am using image.plot function to draw this plot. enter image description here

Based on this plot, I want to adding the brownish region with group of dots. Like on this figure example. enter image description here If anyone ever done this before please let me know. I can give you the data also for sampling. Thanks in advance.

library(ncdf4)
library(chron)
library(lattice)
library(RColorBrewer)
library(fields) # image.plot
library(maps) # map (to add country borders to map)
library(RColorBrewer)

seas <- c("djf","jja","mam","son")
SEA <- c("DJF","JJA","MAM","SON",
         "DJF","JJA","MAM","SON",
         "DJF","JJA","MAM","SON",
         "DJF","JJA","MAM","SON",
         "DJF","JJA","MAM","SON")

# proj <- "rcp26"
proj <- "rcp85"

# period <- "2021-2050"
period <- "2070-2099"

param <- "tas"
#data dir
path <- paste("E:/plot/RCM/",proj,"/",param,"/",sep="")
setwd(dir=path)
file_all <- list.files(pattern=glob2rx("*70*.nc"))
# model_name <- c("CNRM-ALADIN63","ECEARTH-CCLM","HADGEM-HIRHAM",
#                 "MPI-RACMO","NORESM-REMO")

model_name <- c("CNRM-ALADIN63","CNRM-ALADIN63","CNRM-ALADIN63",
                "CNRM-ALADIN63","ECEARTH-CCLM","ECEARTH-CCLM",
                "ECEARTH-CCLM","ECEARTH-CCLM","HADGEM-HIRHAM","HADGEM-HIRHAM",
                "HADGEM-HIRHAM","HADGEM-HIRHAM","MPI-RACMO","MPI-RACMO",
                "MPI-RACMO","MPI-RACMO","NORESM-REMO","NORESM-REMO",
                "NORESM-REMO","NORESM-REMO")


for (fileno in 1:length(file_all)) {
  ncint <- nc_open(file_all[fileno])
  # Lonlat time ---------------------------------
  # get longitude and latitude
  lon <- ncvar_get(ncint,"lon")
  lat <- ncvar_get(ncint,"lat")
  time <- ncvar_get(ncint,"time")
  # Edit Variable ---------------------------------
  #Define Variables
  tas_array <- ncvar_get(ncint,varid=param)
  # Data show ---------------------------------
  tas_slice <- (tas_array)
  # range(tas_slice,na.rm=T)
  # Plot section ---------------------------------
 # brks <- seq(-5,5,0.5) #tas
  # brks <- seq(-8,8,1) #tasmin
  brks <- seq(0,10,1) #tasmax
  # brks <- seq(-4,12,1) #asymetric
  # length(brks)
  
  colorscale <- colorRampPalette(brewer.pal(11, "OrRd"))(length(brks)-1)
  
  # colorscale <- rev(colorRampPalette(brewer.pal(11, "RdBu"),bias=0.41)(length(brks)-1))
  
# Saving Figures
fig<- paste("E:/plot/RCM/",proj,"/figures/",param,"/change-",param,"-",proj,"-",period,"-",
              SEA[fileno],"-",model_name[fileno],".png",sep="")
  jpeg(file=fig,units="in", width=18, height=10, res=300)
  # windows()
  image.plot(lon,lat,tas_slice,
             col=colorscale,breaks=brks,lab.breaks=brks,
             xaxt="n", yaxt="n", ann=FALSE,horizontal=F)
  map(database="world", add=TRUE)
  # we create customized axes (e.g., labels are added to every 20th degrees)
  axis(side=1, at=seq(-180,177.5,10), labels=seq(-180,177.5,10))
  axis(side=2, at=seq(-80,80,10), labels=seq(-80,80,10), las=3)
  # we add longitudes and latitudes to the map
  # abline(h=seq(-80,80,10), v=seq(-180,177.5,10), lty=2)
  title(main=paste(SEA[fileno],proj,param,model_name[fileno],period,
                   sep=" "),
        line=2,cex.lab=1, cex.axis=1.5, cex.main=2, cex.sub=1.5)
  mtext("degC ", side=4, line=5,cex=1.5)
  graphics.off()
  
}

0 Answers0