[R] Problems using Internal filledcontour: "dimension mismatch"
Jason Rupert
jasonkrupert at yahoo.com
Mon Nov 22 05:48:18 CET 2010
In order to gain a bit more control over the fill contour functionality I'm
trying to use the Internal filledcontour function. I wasn't able any
documentation on this function and only one reference to it.
I believe the code shown below is close because all the dimensions seem to be
correct, but I'm still getting a "dimension mismatch" error and the filled
contour doesn't occur. Here is a listing of the actual dimensions:
> length(ak.fan$y)
[1] 40
> dim(ak.fan$y)
NULL
> length(ak.fan$y)
[1] 40
> length(ak.fan$x)
[1] 40
> dim(ak.fan$z)
[1] 40 40
> length(lev.sd.vol)
[1] 5
> length(color_vals_green_to_yellow_to_red)
[1] 20
Note that I did try to use terrain.colors, but that also seemed to produce the
same error. I also replaced all the NA values hoping that would help work
around this error. I'm kind of coming to the end of my guesses about how to
work around this error, so any feedback and advice is greatly appreciated.
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] )
ak.fan.original<-ak.fan
# Get rid of all the NA values and replace with zero values...
ak.fan$z[which(is.na(ak.fan$z))]<-0.0
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)
lev.sd.vol <- pretty(range(na.omit(unique(as.numeric(ak.fan$z)))), 4)
.Internal(filledcontour(as.double(ak.fan$y), as.double(ak.fan$x),
as.double(ak.fan$z), as.double(lev.sd.vol), col =
color_vals_green_to_yellow_to_red))
More information about the R-help
mailing list