library('ggmap') library('ggplot2') library('geosphere') library('curl') library('stringr') library('PostcodesioR') library('qdapTools') options(width=200) df=read.csv('mb.csv', header=FALSE) df=df[!(df$V2>2000),] match=read.csv('postcodes2.csv',header=TRUE) match2=read.csv('LSOA2011_AvPTAI2015.csv',header=TRUE) match=subset(match,select=c(Postcode,LSOA.Code)) match2=subset(match2,select=c(LSOA2011,AvPTAI2015)) #head(match) df$postcode <- NA for (i in c(1:length(df[,1]))){ lat=df[i,]$V3 lon= df[i,]$V4 df[i,]$postcode = reverse_geocoding(lon, lat)[[1]][[1]] } #head(df) df$lsoa = lookup(df$postcode,match) #head(df) df$AvPTAI = lookup(df$lsoa,match2) df=df[complete.cases(df), ] df[order(df$AvPTAI, decreasing = FALSE), ] df=df[- grep("Croydon", df$V1),] #df$V2 #df$AvPTAI pdf('go.pdf') ggplot(df, aes(y=as.numeric(V2), x=as.numeric(AvPTAI)))+geom_point() dev.off() #head(df) #for (i in c(1:length(df[,1]))){ # df[i,]$diff = df[1,]$diff=distm(c(df[1,]$V4,df[1,]$V3), c(0, 50), fun = distHaversine) #} #df=df[!(df$V2>800),] #df=df[order(df$V2, decreasing = FALSE), ] #api='c2cacd59df6bacd1c12d0dab637d93b0' #lon1=toString(df[3,]$V4) #print(lon1) #lat1=toString(df[3,]$V3) #print(lat1) #lat2='51.5239' #lon2='0.1097' #for (i in c(1:length(df[,1]))){ #for (i in c(1,2)){ # df[1,]$index = 1 # time=substr(rawToChar(curl_fetch_memory((gsub(" ","",paste("https://developer.citymapper.com/api/1/traveltime/?startcoord=",toString(df[i,]$V3),"%2C",toString(df[i,]$V4),"&endcoord=",lat2,"%2C",lon2,"&time=2014-11-06T19%3A00%3A02-0500&time_type=arrival&key=",api))))$content),1,26) # print(time) # print(df[1,]$index) #} # call=(gsub(" ", "", call)) # req = curl_fetch_memory(call) # z=rawToChar(req$content) # time = substr(z, 25, 26) # df[i,]$time = time # df[i,] #df[i,]$pay = as.numeric(paste( unlist(amort.table(Loan=df[i,]$V7,n=df[i,]$rem,i=((df[i,]$V5/100)/12))[1]))[1]) #call=(gsub(" ", "", call)) #print(call) #req = curl_fetch_memory(call) #z=rawToChar(req$content) #time = substr(z, 25, 26) #print(time) #length(df[,1]) #head(df,n=100) #pdf("mb2.pdf", width=10, height=5) #ggplot(df, aes(x=V2)) + geom_density() #scale_x_continuous(limits=c(-10,40)) #dev.off() #on <- c(-38.31,-35.5) #lat <- c(40.96, 37.5) #df <- as.data.frame(cbind(lon,lat)) #df = subset(df, select = c(V3, V4)) # getting the map #mapgilbert <- get_map(location = c(lon = mean(df$V4), lat = mean(df$V3)), # zoom = 10, # maptype = "roadmap", # scale = 4) # plotting the map with some points on it #pdf('mbmap.pdf') #ggmap(mapgilbert) + # geom_point(data = df, aes(x = V4, y = V3, fill = "red", alpha = 0.8), size = 5, shape = 21) ## guides(fill=FALSE, alpha=FALSE, size=FALSE) #dev.off()