[R] Possible to "add" filled.contour(...) to existing plot?

Jason Rupert jasonkrupert at yahoo.com
Sun Nov 21 04:59:51 CET 2010


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)



More information about the R-help mailing list