Jason Rupert
2010-Nov-21 03:59 UTC
[R] Possible to "add" filled.contour(...) to existing plot?
By any chance is it possible to "add" filled.contour(...) to an existing plot like you can do using image(..., add = TRUE). I looked at the filed.contour(...) and levelplot(...) documentation, but it didn't seem to be possible. I would like to add filled.plot(...) as shown below instead of using the image(...). Filled.contour seems to provide the smoothing interpolation that is not possible via image(...). In addition, I would like to be able to add a grid via grid(...) to the plot and then add the filled contour. Thanks for any insights and feedback... # Example code... library(akima) hyp_distance<-seq(1,15) angle_deg_val<-seq(0,15) x_distance_val<-NULL y_distance_val<-NULL for(ii in 1:length(hyp_distance)) { for(jj in 1:length(angle_deg_val)) { x_distance_tmp<-hyp_distance[ii]*cos(angle_deg_val[jj]*pi/180) y_distance_tmp<-hyp_distance[ii]*sin(angle_deg_val[jj]*pi/180) x_distance_val<-c(x_distance_val, x_distance_tmp) y_distance_val<-c(y_distance_val, y_distance_tmp) } } temperature_vals<-rnorm(length(x_distance_val), 75, 2) temp_samples<-cbind(x_distance_val, y_distance_val, temperature_vals) temp_samples_DF<-data.frame(x = x_distance_val, y = y_distance_val, z = temperature_vals) ak.fan <- interp(temp_samples[,1], temp_samples[,2], temp_samples[,3] ) length_val<-floor(max(temperature_vals) - min(temperature_vals))*2 color_vals_red_to_yellow_to_green<-colorRampPalette(c("red", "yellow", "green"), space="Lab")(length_val) color_vals_green_to_yellow_to_red<-colorRampPalette(c("green", "yellow", "red"), space="Lab")(length_val) plot(1,1, col = 0, xlim = c(min(x_distance_val), max(x_distance_val)), ylim = c(min(y_distance_val), max(y_distance_val)), xlab = "Room X Position (FT)", ylab = "Room Y Position (FT)", main = "Room Temp vs Position") grid() # filled.contour(ak.fan, col = color_vals_red_to_yellow_to_green) # filled.contour(ak.fan, col = color_vals_green_to_yellow_to_red) # image(ak.fan, col = color_vals_red_to_yellow_to_green, add = TRUE) image(ak.fan, col = color_vals_green_to_yellow_to_red, add = TRUE)
Hi Jason! I have suggested in another post how to plot more than one filled.contour graph at the same device. Maybe you could adapt that script to you specific problem. Look my suggestion at: http://r.789695.n4.nabble.com/several-Filled-contour-plots-on-the-same-device-td819040.html#a2332041 -- Gustavo Requena PhD student - Laboratory of Arthropod Behavior and Evolution Universidade de S?o Paulo Correspondence adress: a/c Glauco Machado Departamento de Ecologia - IBUSP Rua do Mat?o - Travessa 14 no 321 Cidade Universit?ria, S?o Paulo - SP, Brasil CEP 05508-900 Phone number: 55 11 3091-7488 http://ecologia.ib.usp.br/opilio/gustavo.html
Seemingly Similar Threads
- Alternatives to image(...) and filled.contour(...) for 2-D filled Plots
- Problems using Internal filledcontour: "dimension mismatch"
- Using image/contour with unevenly spaced data...
- Setting a Red->Yellow->Green Color Transition in Image(...) with yellow corresponding with the Mean Value...
- 4. Rexcel (Luis Felipe Parra)-how to run a code from excel