My goal is to create an interpolation map of some output model results that are mapped on a deformed mesh (from a numerical simulation). The model results are in an x-y plane (representing coordinates) with a variable-z to interpolate, however the coordinates are irregularly spaced and have an upper boundary that should be respected.

I am able to plot exactly what I was using a program called Tecplot, however I can only do one image at a time. Using Tecplot is extremely tedious and thus I would like to automate this in R. Here is what I want:

what I want

I am currently using this code below in R to do the same thing however my results are less than ideal and I would like to improve my R code.

Here is the link to some example data: link.

Here is my code I am currently using and the non-ideal output of that code:




#interpolate with akima
inter<-interp(x=data$x, y=data$y, z=data$z,xo=seq(min(data$x), max(data$x),   length = 300),yo=seq(min(data$y), max(data$y), length = 100),extrap=FALSE)

filled.contour(inter,xlim=c(50,150),ylim=c(5,17),color.palette=colorRampPalette(c("Red", "blue")),xlab = "Distance Across River",ylab = "Elevation", main = "Pressure",key.title = title(main = "Pressure (m)", cex.main = 1)) 

#contouring with melt and ggplot
df <- melt(inter$z, na.rm = TRUE)
names(df) <- c("x", "y", "z")
df$x <- inter$x[df$x]
df$y <- inter$y[df$y]

ggplot(data = df, aes(x = x, y = y, z = z)) +
  geom_tile(aes(fill = z)) +
  stat_contour() +
  ggtitle("Pressure") +
  xlab("Distance Across River") +
  ylab("Elevation") +
  scale_fill_continuous(name = "Pressure (m)",low = "Red", high = "blue") +
  theme(plot.title = element_text(size = 25, face = "bold"),
        legend.title = element_text(size = 15),
        axis.text = element_text(size = 15),
        axis.title.x = element_text(size = 20, vjust = -0.5),
        axis.title.y = element_text(size = 20, vjust = 0.2),
        legend.text = element_text(size = 10))

Here are my non-ideal results with the Akima package: Akima

Here are my non-ideal results with ggplot: GGplot

How can I create an image similar to the one from Tecplot but using R? Notice that in the plots from ggplot and from Akima, the top boundary shape is completely obscured and I want that feature to stand out, and for the interpolation to respect the shape of the top as it is a very important feature.

  • Could you please recover the link to the raw data ? – César Arquero Mar 7 '19 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.