Is it possible to plot unevenly spaced data with image/contour function? Below is an example of the type uneven data that I'm trying to plot with image/contour functions. For example, I would like to have the x-distance on the x-axis and y-distance on the y-axis and then the temperature values determine the color used. Unfortunately this data was sampled such that it is not evenly spaced on a Cartesian plot. I was hoping that image(temp_samples) or contour(temp_samples) or something similar would work, but my attempts didn't succeed. Thanks for any feedback insights and hints... 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.2) temp_samples<-cbind(x_distance_val, y_distance_val, temperature_vals)
David Winsemius
2010-Nov-19 04:42 UTC
[R] Using image/contour with unevenly spaced data...
On Nov 18, 2010, at 10:52 PM, Jason Rupert wrote:> Is it possible to plot unevenly spaced data with image/contour > function? > > Below is an example of the type uneven data that I'm trying to plot > with > image/contour functions. For example, I would like to have the x- > distance on > the x-axis and y-distance on the y-axis and then the temperature > values > determine the color used. Unfortunately this data was sampled such > that it is > not evenly spaced on a Cartesian plot. > > I was hoping that image(temp_samples) or contour(temp_samples) or > something > similar would work, but my attempts didn't succeed. > > Thanks for any feedback insights and hints... > > 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.2) > > temp_samples<-cbind(x_distance_val, y_distance_val, temperature_vals)library(akima) ak.fan <- interp(temp_samples[,1],temp_samples[,2],temp_samples[,3] ) contour(ak.fan) -- David Winsemius, MD West Hartford, CT
Maybe Matching Threads
- Alternatives to image(...) and filled.contour(...) for 2-D filled Plots
- Setting a Red->Yellow->Green Color Transition in Image(...) with yellow corresponding with the Mean Value...
- Problems using Internal filledcontour: "dimension mismatch"
- Possible to "add" filled.contour(...) to existing plot?
- 4. Rexcel (Luis Felipe Parra)-how to run a code from excel