library(akima)
library(ggplot2)

data <- array(rnorm(90 * 10), c(lat = 90, lev = 10))
lat <- 0:89
lev <- c(0, 10, 50, 100, 250, 500, 750, 800, 900, 1000) 

lats <- rep(lat, length(lev))
levels <- sort(rep(lev, length(lat)))
datos <- data.frame(lats = lats, levels = levels, data = as.vector(data))

ggplot(data = datos, aes(x = lats, y = levels, fill = data)) + geom_raster()



#Es esto lo que Roberto quería?
inter_lin = interp(lats, levels, datos$data,
                   xo = seq(min(lats), max(lats), length = 100),
                   yo = seq(min(levels), max(levels), length = 100), 
                   linear = TRUE, extrap = TRUE)
result <- data.frame(x = rep(inter_lin$x, 100),
                     y = sort(rep(inter_lin$y, 100)),
                     z = as.vector(inter_lin$z))
dev.new()
ggplot(data = result, aes(x = x, y = y, fill = z)) + geom_raster()

# Ahora puede seleccionar los niveles y latitudes que quiera.

inter_lin = interp(lats, levels, datos$data,
                   xo = seq(min(lats), max(lats), length = 179),
                   yo = seq(min(levels), max(levels), length = 101),
                   linear = TRUE, extrap = TRUE)
new_lats <- inter_lin$x # uso todas
new_lev <- inter_lin$y[c(1,16,31,46,61,76,91]  


