[R] Alternatives to image(...) and filled.contour(...) for 2-D filled Plots

Ista Zahn izahn at psych.rochester.edu
Mon Nov 22 17:07:43 CET 2010


Hi Jason,
You do not say what you want the alternative to do, so its hard to
know if this will be helpful. But one alternative is

dat <- as.data.frame(ak.fan)
dat <- melt(dat, id.vars=c("x", "y"))

p <- ggplot(dat, aes(x=x, y=variable))
p + geom_tile(aes(fill=value))

-Ista

On Sun, Nov 21, 2010 at 9:04 AM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
>
> By any chance are there any alternatives to image(...) and filled.contour(...)
>
> I used Rseek to search for that very topic, but didn't turn over any leads...
> http://www.rseek.org/?cx=010923144343702598753%3Aboaz1reyxd4&newwindow=1&q=alternative+to+image+and+filled.contour&sa=Search&cof=FORID%3A11&siteurl=www.rseek.org%252F#1238
>
>
> I'm sure there are some out there, but curious about some of the favorites and
> ones folks have had success using.
>
>
> Thanks for any insights and feedback.
>
> I would like to use the alternative 2-D fill function with the example I have
> been messing with in place of image(...) or filled.contour(...):
>
>
>
> 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)
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list