I have a data frame with 5 columns:
N1 <- an integer between c(125,100,80,70,60,50,40,30,20)
N2 <- an integer between c(1,5,10,15,20,25,30,35,40,50,60,80,100)
Type <- Two different types
Rang <- a number
crit <- a character, only one value
N1always more than that N2. Here is an example of the start of my data frame ( Rang_final):
N1 N2 Type rang crit
125 1 SST-T_2m 41.86395 BE_proba
125 1 T_2m-SST 163.41217 BE_proba
100 1 SST-T_2m 32.88181 BE_proba
100 1 T_2m-SST 137.44479 BE_proba
80 1 SST-T_2m 22.57176 BE_proba
80 1 T_2m-SST 112.52334 BE_proba
70 1 SST-T_2m 21.30066 BE_proba
70 1 T_2m-SST 99.65523 BE_proba
60 1 SST-T_2m 18.48731 BE_proba
60 1 T_2m-SST 85.36945 BE_proba
50 1 SST-T_2m 18.60074 BE_proba
50 1 T_2m-SST 71.58960 BE_proba
40 1 SST-T_2m 18.58180 BE_proba
40 1 T_2m-SST 62.82670 BE_proba
30 1 SST-T_2m 20.53982 BE_proba
30 1 T_2m-SST 48.58923 BE_proba
20 1 SST-T_2m 27.15737 BE_proba
20 1 T_2m-SST 36.04175 BE_proba
125 5 SST-T_2m 101.82300 BE_proba
125 5 T_2m-SST 168.69954 BE_proba
100 5 SST-T_2m 91.10644 BE_proba
...
I want to have all this information in only one graph, so I am looking for using ggplot and geom_tileas follows:
p <- ggplot(Rang_final)
p <- (p
+ geom_tile(data=Rang_final[Rang_final$Type=="SST-T_2m",], aes(x=N1, y=N2, fill=rang))
+ geom_tile(data=Rang_final[Rang_final$Type=="T_2m-SST",], aes(x=N2, y=N1, fill=rang))
+ scale_fill_gradient2(name="Rang", low="deepskyblue",mid="yellow",high="red", midpoint=100, na.value = "grey50")
+ theme(axis.title.x = element_text(size=14, face="bold"),
axis.title.y = element_text(size=14, face="bold"),
strip.text.x = element_text(size=14, face="bold"),
strip.text.y = element_text(size=14, face="bold"),
axis.text=element_text(size=14),
axis.title.y=element_text(size=14, face="bold"),
legend.key=element_rect(size=0.5, colour="black"),
legend.text=element_text(size=10),
legend.margin=unit(0,"lines"),
legend.key.size=unit(0.8,"cm"),
legend.text.align=0)
+ theme_bw()
)
print(p)
And this is what I get (class N1 and N2 is numeric):

But I want to remove blank lines, so I tried to convert N1 and N2 as factors:
Rang_final$N1 <- factor(Rang_final$N1, levels = c("20", "30", "40", "50", "60", "70", "80", "100", "125") ,ordered = TRUE)
Rang_final$N2 <- factor(Rang_final$N2, levels = c("1", "5", "10", "15", "20", "25", "30", "35", "40", "50", "60", "80", "100", "125") ,ordered = TRUE)

But here my numbers are not in ascending order.
Here I also used N1 and N2 as factors, but I could not manage to have two different types on the same chart with this scale:
p <- ggplot(Rang_final, aes(x=N1, y=N2))
p <- (p
+ geom_tile(aes(fill=rang))
+ facet_grid(Type ~ crit, scales="free")
+ scale_fill_gradient2(name="Rang", low="deepskyblue",mid="yellow",high="red", midpoint=100, na.value = "grey50")
+ theme(axis.title.x = element_text(size=14, face="bold"),
axis.title.y = element_text(size=14, face="bold"),
strip.text.x = element_text(size=14, face="bold"),
strip.text.y = element_text(size=14, face="bold"),
axis.text=element_text(size=14),
axis.title.y=element_text(size=14, face="bold"),
legend.key=element_rect(size=0.5, colour="black"),
legend.text=element_text(size=10),
legend.margin=unit(0,"lines"),
legend.key.size=unit(0.8,"cm"),
legend.text.align=0)
+ theme_bw()
)

Can someone help me?