Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to plot delta changes and it signification in the same map (spatialPlot) #8

Open
abelcentella opened this issue May 27, 2021 · 7 comments

Comments

@abelcentella
Copy link

Hi

I calculated the delta change between the climatologies for history (climH) and future (climF) precip and put the result on a grid (change)
climH <-climatology(subH)
climF <- climatology(subF)
change<-gridArithmetics(climF,climH,climH,c,operator = c("-","/","*"))

As I don't found a way (in climate4R) to estimate the statistical signification of the changes I did this with my own script based on t.test using subH and subF grids. Then I produced a grid (named r) with 1 and 0 (1 significant). After that I applied sig<-easyVeri2grid(r,subH) and then sigpoint<-map.stippling(sig,threshold = 1, condition = "GE",pch=16,col="black",cex=0.5).

Finally, I got a proper plot with the precip changes and points where the changes are significant. I used the following

spatialPlot(change,main=list(c("Precip Changes 2021-2040 vs 1961-1990"),cex=2),
xlab=list("Longitude",cex=1.5),ylab=list("Latitude",cex=1.5),
colorkey = list(space = "right",title="(%)",cex=2),
backdrop.theme = "coastline",scales=list(draw=TRUE,cex=1),
col.regions = colorRampPalette(colraindelta),
set.min = -50,set.max=50,sp.layout=list(sig_points))

The above is just for one season or a month. Thus as I want to make a multipanel plot using spatialPlot with a multigrid I create a multigrid using multg<-makeMultiGrid(changes 1..12,skip.temporal.check = TRUE) and made a list of 12 with the respective sig_points. Then

mons<-c("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")

spatialPlot(change,main=list(c("Precip Changes 2021-2040 vs 1961-1990"),cex=2),
xlab=list("Longitude",cex=1.5),ylab=list("Latitude",cex=1.5),
colorkey = list(space = "right",title="(%)",cex=2),
names.attr=mons,as.table=TRUE,
backdrop.theme = "coastline",scales=list(draw=TRUE,cex=1),
col.regions = colorRampPalette(colraindelta),
set.min = -50,set.max=50,sp.layout=list(sig_points))

I got a multipanel plot with the changes for every month but the stippling is always the same for every panel. I believe that I'm doing something wrong.

Can somebody explain to me what is wrong or if there is another way to plot the change field with the significance?

@jorgebanomedina
Copy link

**Hi,

The problem is in the sig_points object, since it is a list of 12 (one per season). I recommend you to loop over the months and add a member of sig_points object one at a time to spatialPlot, such that:**

figs <- lapply(1:12, FUN = function(z) {
# where change_z is the change of month z, e.g., change_1 is the change of month "JAN"
spatialPlot(change_z, backdrop.theme = "coastline",
sp.layout=list(sig_points[[z]]),
.... "your other plotting parameters")
})

Finally you can call the figs object that store the spatial maps, with grid.arrange:
library(gridExtra)
grid.arrange(grobs = figs, ncol = 4)

By the way, climate4R.value do not capsulate the t-test statistic, but you can consider the p-value of the KS-statistic which can be computed by setting measure.code = "ts.ks.pval" in valueMeasure function, as an alternative to the t-test. This is just in case you want to fully depend on climate4R, you approach with the t-test and easyveri2grid seems reasonable for me.

Please let me know if you attain your desired plots.

Cheers,

Jorge

@jbedia
Copy link
Member

jbedia commented May 31, 2021

Hi,
"[...] and made a list of 12 with the respective sig_points".
At this point, you must include the argument which in each element of the list, so the first stippling goes to subpanel 1 (which = 1), the second to subpanel 2 (which = 2) and so on. There is an example (not exactly your case, but it may help) in ?map.stippling. I hope this helps.

@abelcentella
Copy link
Author

**Hi,

The problem is in the sig_points object, since it is a list of 12 (one per season). I recommend you to loop over the months and add a member of sig_points object one at a time to spatialPlot, such that:**

figs <- lapply(1:12, FUN = function(z) {

where change_z is the change of month z, e.g., change_1 is the change of month "JAN"

spatialPlot(change_z, backdrop.theme = "coastline",
sp.layout=list(sig_points[[z]]),
.... "your other plotting parameters")
})

Finally you can call the figs object that store the spatial maps, with grid.arrange:
library(gridExtra)
grid.arrange(grobs = figs, ncol = 4)

By the way, climate4R.value do not capsulate the t-test statistic, but you can consider the p-value of the KS-statistic which can be computed by setting measure.code = "ts.ks.pval" in valueMeasure function, as an alternative to the t-test. This is just in case you want to fully depend on climate4R, you approach with the t-test and easyveri2grid seems reasonable for me.

Please let me know if you attain your desired plots.

Cheers,

Jorge

Hi Jorge,

Thanks a lot. I understood the point. However I followed the suggestion fro Bedia which is simplest for my specific case. I works for me and the plots are find now. Nevertheless I will use your approach in other scripts we are building.
Re ts.ks.pval I was trying to install the VALUE packaged as recommended but I got an error.

devtools::install_github("SantanderMetGroup/VALUE")
Downloading GitHub repo SantanderMetGroup/VALUE@HEAD
Error in utils::download.file(url, path, method = method, quiet = quiet, :
download from 'https://api.github.com/repos/SantanderMetGroup/VALUE/tarball/HEAD' failed

Regards

Abel

@abelcentella
Copy link
Author

Hi,
"[...] and made a list of 12 with the respective sig_points".
At this point, you must include the argument which in each element of the list, so the first stippling goes to subpanel 1 (which = 1), the second to subpanel 2 (which = 2) and so on. There is an example (not exactly your case, but it may help) in ?map.stippling. I hope this helps.

Hi Joaquin
Thanks you very much, I got the right plots

@jorgebanomedina
Copy link

Hi,

Try devtools::install_github("SantanderMetGroup/[email protected]")

Regards,

Jorge

@abelcentella
Copy link
Author

abelcentella commented Jun 1, 2021 via email

@abelcentella
Copy link
Author

abelcentella commented Jun 1, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants