I have two curves of same count of points filled using approx function, for both x and y values separately for each curve. Both x and y axis values are logarithmic, so I convert back to normal decimal scale when approximating and interpolating. Black and blue lines are original lines and the red one is interpolated in between. As you can see the red line doesn't mimic the bend on the right side, since interpolation is performed based on assumption that each x and y pair are the closest.
Is there any way how to perform interpolation between curves in R based on the real closest points in between? Maybe there exists algorithms for that? Anything would be useful as I am not sure how it is called in mathematics.
base="ftp://cdsarc.u-strasbg.fr/pub/cats/J/A+A/508/355/ms/"
setwd("~/Desktop")
file1=paste(base,"z001y23_1.60.dat",sep="")
file2=paste(base,"z001y23_1.70.dat",sep="")
cols=c("no","age","logL","logTef", "grav","stage")
ncol <- length(count.fields(file=file1, sep = ","))
second=read.table(file=file1,fill=T, blank.lines.skip=F, skip=2, header=F, strip.white=T, col.names = paste("V", seq_len(ncol)))
second$V.6<-second$V.23
colnames(second) <-cols
second$logL=as.numeric(second$logL)
#performing some filtering of data here
pos1=which(second$stage == "trgb")[1]
second=second[1:pos1,]
ncol <- length(count.fields(file=file2, sep = ","))
first=read.table(file=file2,fill=T, blank.lines.skip=F, skip=2, header=F, strip.white=T, col.names = paste("V", seq_len(ncol)))
first$V.6<-first$V.23
colnames(first) <-cols
#performing some filtering of data here
pos2=which(first$stage == "trgb")[1]
first=first[1:pos2,]
#plotting data
len=max(c(min(first[[4]]),min(second[[4]])))
first=first[first[[4]]>len,]
second=second[second[[4]]>len,]
plot(second[[4]],second[[3]],t="l",xlim=rev(range(second[[4]])),xlab="x",ylab="y")
lines(first[[4]],first[[3]],t="l",col="blue")
n=max(c(length(second[[4]]),length(first[[4]])))
#approximating missing points
xf1 <- approx(10^second[[4]],n=n)
yf1 <- approx(10^second[[3]],n=n)
xf2 <- approx(10^first[[4]],n=n)
yf2 <- approx(10^first[[3]],n=n)
#calculating interpolated line
ratio=2
s1<-log10((xf1$y-xf2$y)/ratio+xf2$y)
s2<-log10((yf1$y-yf2$y)/ratio+yf2$y)
lines(s1,s2, col ="red")