I want to create Scatter Plot Matrix using ggplot2. Partially I coped with my problem. I managed to create three-part graph using ggplot2: the lower triangle - Scatterplot, diagonally - variable names and the upper triangle - correlation coefficient (R^2). Below I give piece of my data + code generating my chart. My data:
f =
C xval V yval corr V1
1 1622 1 1622 1 2ng
1 1622 2 1639 0.997 2ng
1 1622 3 1584 0.992 2ng
1 1622 4 1549 0.99 2ng
1 1622 5 1541 0.993 2ng
1 1622 6 1543 0.994 2ng
1 1622 7 1530 0.988 2ng
2 1639 1 1622 0.997 5ng
2 1639 2 1639 1 5ng
2 1639 3 1584 0.997 5ng
2 1639 4 1549 0.997 5ng
2 1639 5 1541 0.998 5ng
2 1639 6 1543 0.998 5ng
2 1639 7 1530 0.995 5ng
3 1584 1 1622 0.992 10ng
3 1584 2 1639 0.997 10ng
3 1584 3 1584 1 10ng
3 1584 4 1549 0.997 10ng
3 1584 5 1541 0.995 10ng
3 1584 6 1543 0.999 10ng
3 1584 7 1530 0.999 10ng
4 1549 1 1622 0.99 15ng
4 1549 2 1639 0.997 15ng
4 1549 3 1584 0.997 15ng
4 1549 4 1549 1 15ng
4 1549 5 1541 0.998 15ng
4 1549 6 1543 0.998 15ng
4 1549 7 1530 0.998 15ng
5 1541 1 1622 0.993 30ng
5 1541 2 1639 0.998 30ng
5 1541 3 1584 0.995 30ng
5 1541 4 1549 0.998 30ng
5 1541 5 1541 1 30ng
5 1541 6 1543 0.998 30ng
5 1541 7 1530 0.995 30ng
6 1543 1 1622 0.994 60ng
6 1543 2 1639 0.998 60ng
6 1543 3 1584 0.999 60ng
6 1543 4 1549 0.998 60ng
6 1543 5 1541 0.998 60ng
6 1543 6 1543 1 60ng
6 1543 7 1530 0.998 60ng
7 1530 1 1622 0.988 100ng
7 1530 2 1639 0.995 100ng
7 1530 3 1584 0.999 100ng
7 1530 4 1549 0.998 100ng
7 1530 5 1541 0.995 100ng
7 1530 6 1543 0.998 100ng
7 1530 7 1530 1 100ng
And code:
g <- ggplot(data = f, aes(x=xval, y=yval))+
geom_point(data = f[(xtfrm(f$C)<xtfrm(f$V)),], colour = "darkblue", size = 1.5)+
geom_smooth(data = f[(xtfrm(f$C)<xtfrm(f$V)),], aes(colour = "red"), method="lm", size = 0.1)+
geom_text(data = f[(xtfrm(f$C)==xtfrm(f$V)),], aes(x = 4000, y = 4000, label = paste(V1)), size = 10, colour="red")+
geom_tile(aes(fill=corr))+
geom_text(data = f[(xtfrm(f$C)>xtfrm(f$V)), ], aes(x = 4000, y = 4000, label = corr), size = 10)+
coord_cartesian(xlim=c(0,8000), ylim=c(0,8000))+
facet_grid(V~C, space = "fixed") +
theme(panel.grid.major = element_blank(), strip.background = element_blank(), strip.text.y = element_blank(), strip.text.x = element_blank(), legend.position = "none")
g
However, I have got a problem for improving the appearance of the graph. I want to separate part of the graph with different background colour for example: white background for scatters, gray for variable names and blue for correlation coeff. Does anyone know how to do it? Is it possible or I have to create each part of graph separately?