[R] Reshpaing for xyplot() or ggplot()

Agustin Lobo aloboaleu at gmail.com
Tue Dec 22 11:34:20 CET 2009


Dear list,

I have 2 data sets such as:
 > head(calib20090730b)
   color  XR  XG  XB L1_1  L1_2 L1_3
1     1  87  55  62  116 124.0  100
2     2 164 125 134  204 203.0  153
3     3 118  64  98  157 101.0  139
4     4  65  72  72  102 111.0  135
5     5 142  95 112  176 161.5  133
6     6  89 113 112  125 128.0  195
 > head(refpanel)
   color    B    G    R NIR1 NIR2
1     1 0.07 0.10 0.17 0.29 0.43
2     2 0.24 0.32 0.63 0.85 0.87
3     3 0.34 0.19 0.15 0.40 0.86
4     4 0.06 0.14 0.11 0.14 0.18
5     5 0.42 0.22 0.31 0.56 0.86
6     6 0.42 0.47 0.20 0.24 0.43
 >

My goal is to use either xyplot() or ggplot (qplot() ?) or
any other better way for simplifying the following syntax and making a
nicer graphic:
par(mfrow=c(3,5),pty="s")
plot(calib20090730b$XR,refpanel$B,xlab="rawR",ylab="refB")
plot(calib20090730b$XR,refpanel$G,xlab="rawR",ylab="refG")
plot(calib20090730b$XR,refpanel$R,xlab="rawR",ylab="refR")
plot(calib20090730b$XR,refpanel$NIR1,xlab="rawR",ylab="refNIR1")
plot(calib20090730b$XR,refpanel$NIR2,xlab="rawR",ylab="refNIR2")

and so on for calib20090730b$XG and calib20090730b$XB

I've used melt() in this way:
 > datos1 <- melt(calib20090730b,id="color")
 > datos2 <- melt(refpanel,id="color")
 > datos <- rbind(datos1,datos2)
 > head(datos)
   color variable value
1     1       XR    87
2     2       XR   164
3     3       XR   118
4     4       XR    65
5     5       XR   142
6     6       XR    89

and cast() to create
 > datos3 <- cast(datos,...~variable)
 > head(datos3)
   color  XR  XG  XB L1_1  L1_2 L1_3    B    G    R NIR1 NIR2
1     1  87  55  62  116 124.0  100 0.07 0.10 0.17 0.29 0.43
2     2 164 125 134  204 203.0  153 0.24 0.32 0.63 0.85 0.87
3     3 118  64  98  157 101.0  139 0.34 0.19 0.15 0.40 0.86
4     4  65  72  72  102 111.0  135 0.06 0.14 0.11 0.14 0.18
5     5 142  95 112  176 161.5  133 0.42 0.22 0.31 0.56 0.86
6     6  89 113 112  125 128.0  195 0.42 0.47 0.20 0.24 0.43

but I'm stuck there. I think that I would need something like

   color  XR  XG  XB L1_1  L1_2 L1_3  RefVal Band
1     1  87  55  62  116 124.0  100 0.07     B
2     2 164 125 134  204 203.0  153 0.24     B
3     3 118  64  98  157 101.0  139 0.34     B
4     4  65  72  72  102 111.0  135 0.06     B
5     5 142  95 112  176 161.5  133 0.42     B
6     6  89 113 112  125 128.0  195 0.42     B
...

so that I could use
xyplot(RefVal ~ XR | Band, data=datosX)

but do not get to that. Don't even know if the problem is at the melt() or 
cast() level. I've also tried reshape(). Any help, advice and/or pointer to an 
appropriate tutorial
would be appreciated.


Thanks

Agus

-- 
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster




More information about the R-help mailing list