2

Could we use R to plot this figure?One grid cell with two values?

Heatmaps showing the Kuiper distance values (upper-left triangles) and the (1-PSS) values (bottom-right triangles)

enter image description here

Actually, this figure has two correlations coefficients, the top left triangle is one and the bottom right triangle is another one. Does anyone know how to plot this figure in R?

I have tried to use these packages, but I can't make it.

library(corrplot) 
library(ggcorrplot)
library(GGally)
s__
  • 9,270
  • 3
  • 27
  • 45
Hong
  • 49
  • 6
  • 2
    Please make this question *reproducible*. This includes sample code (including listing non-base R packages), sample data (e.g., `dput(head(x))`), and expected output. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. Otherwise this is very close to "*recommend or find a book, tool, software library*", which on SO is [off-topic](https://stackoverflow.com/help/on-topic). – r2evans Sep 26 '18 at 02:19
  • This appears identical to your [previous question](https://stackoverflow.com/questions/52416978/could-we-use-r-to-plot-this-figure-one-grid-cell-with-two-variables), which was closed for being unclear. Do read through the references r2evans provided above; they should give you some idea for how to improve the question. – Z.Lin Sep 26 '18 at 02:45
  • asking the same question again I see what you are doing ;) I think it is clear two values within a cell for the relationship between two variables. – R. Prost Sep 26 '18 at 05:33
  • What does the split in a single square mean? – Naive_Natural2511 Sep 26 '18 at 12:07

1 Answers1

0

Here an example that works well for me.

## First of all define your palette colours with:

### I assume that the dimension of PSS_values= Kuiper_distance_values=8,16 

### "ncol1" will be the palette colours for Kuiper distance values (upper-left triangles) while the "ncol2" will for the (1-PSS) values (bottom-right triangles)



color.gradient <- function(x, colors=c(mypal), colsteps=100) {return(colorRampPalette(colors) (colsteps) [ findInterval(x, seq(min(x),max(x), length.out=colsteps)) ] )}


ncol1=matrix(color.gradient(as.vector(Kuiper_distance_values[,rev(1:16)])),nrow=8,ncol=16)

ncol2=matrix(color.gradient(as.vector(PSS_values[,rev(1:16)])),nrow=8,ncol=16)


y=seq(1,16),x=seq(1,8)

par(mfrow=c(1,1))


par(oma=c(15,8,4,2))

plot(1,1,xlim=c(0.75,8.25),ylim=c(0.75,16.25), type="n",bty="n" ,xaxt="n",yaxt="n",xlab="",ylab="")



for(i in 1:8){ 
for(j in 1:16){
polygon(x[i]-0.5+c(0,1,1),y[j]-0.5+c(0,0,1),col=ncol1[i,j])

polygon(x[i]-0.5+c(0,1,0),y[j]-0.5+c(0,1,1),col=ncol2[i,j])

}}


Listofclimateindex=c("Annuelmean","DJFmean","JJAmean","etc")
Listofclimatemodels=c("ERA5I","MERRA2","CRCM5-OUR","CRCM5-UQAM","CanRCM4","HIRHAM5","RCA4","RegCM4","WRF","ENSmean")

axis(side=2, at= 1:16,labels=rev(Listofclimatemodels), las=1, cex.axis=2,font=2)

axis(side=3, at= 1:8,labels=Listofclimateindex,las=1, cex.axis=2.5,font=2)


abline(h=seq(from=0.5,to=ncol(PSS_values[,rev(1:16)])+0.5,by=1),lty=1,col="white",lwd=1)

abline(v=seq(from=0.5,to=nrow(PSS_values[,rev(1:16)])+0.5,by=1),lty=1,col="white",lwd=1)