I've been helped by @Ista to produce the follow code. From this code, I now need to save:
- Q1: the average 'm' value at nR = 0 for each of the 8 scatter plots;
- Q2: the value of the slope of the regression (shown here with stat_smooth) for only a subset of the data (let's say, all data from nR = 0 to nR = 50). As you can see in the example, the regression is computed for the whole dataset;
- data should be saved as to be reused for another visualisation with ggplot2. I'm not sure if this point matters, but I'm mentioning it just in case.
require(reshape2)
library(ggplot2)
library(RColorBrewer)
md = read.csv(file="http://dl.dropboxusercontent.com/u/73950/rob-136.csv", sep=",", header=TRUE)
dM = melt(md,c("id"))
# split variable out into its components
dM <- cbind(dM,
colsplit(dM$variable,
pattern = "_",
names = c("Nm", "order", "category")))
# no longer need variable, as it is represented by the combination of Nm, order, and category
dM$variable <- NULL
# rearrange putting category in the columns
dM <- dcast(dM, ... ~ category, value.var = "value")
# plot
p = ggplot(dM, aes(x=nR ,y=m))
p = p + scale_y_continuous(name="m")+ scale_x_continuous(name="nR") + xlim(0,136)
p = p + facet_grid(order~Nm)+ ggtitle("Title")
p = p + stat_bin2d(bins=50)
myPalette <- colorRampPalette(rev(brewer.pal(11, "Spectral")))
p = p + scale_fill_gradientn(colours = myPalette(100))
p = p + theme(legend.position="none")
p = p + stat_smooth(method = 'lm')
p
I hope this is clear enough, but please let me know if I'm not making sense...
Cheers!