Can you explain this code?
What is the use of x1 and x2
I want to create contour from this code.
please explain the use of interp().
how can this code be helpful in plotting the contour?
we have text file in which we have three separate columns with lat long. thow to use interp()?
f=read.table("data2_input.txt",sep="\t",header=T)
attach(f)
library(akima)
library(reshape2)
c1=length(f[1,])
r1=length(f[,1])
lat=0,long=0,conc=0,x1=0 y1=0 midx=0 x2=0 y2=0 midy=0
conc=0 r=r1
c=c1
lat=f[,1]
long=f[,2]
conc=f[,3]
ak=interp(long,lat,conc, xo=seq(min(long),max(long),length=200),yo=seq(min(lat),max(lat),length=75))
mak=melt(ak$z)
names(mak)=c('x','y','value')
mak$lon=ak$x[mak$x]
mak$lat=ak$y[mak$y]
lon_diff=round(ak$x[2]-ak$x[1],5)
lat_diff=round(ak$y[2]-ak$y[1],5)
mak1=mak[,3:5]
mak1=subset(mak1,mak1$value!='NA')
names(mak1)=c('Concentration','Longitude','Latitude')
/* why use x1 and x2*/
x1=round(mak1$Latitude-lat_diff/2,4)
y1=round(mak1$Longitude-lon_diff/2,4)
x2=round(mak1$Latitude+lat_diff/2,4)
y2=round(mak1$Longitude+lon_diff/2,4)
/*why use round function*/
z1=as.data.frame(cbind(x1,y1,x2,y2,round(mak1$Latitude,4),round(mak1$Longitude,4),round(mak1$Concentration,4)))
names(z1)=c('latitude_x1','longitude_y1','latitude_x2','longitude_y2','midx','midy','dvalue')
write.csv(z1,'data2_output.csv',row.names=F,quote=F)