Commit 37c64084 authored by numeroteca's avatar numeroteca

calculates location of VUT Valencia in distritos y barrios

parent da225d3a
......@@ -6,6 +6,7 @@ library("raster")
library("sp")
# restart R .rs.restartR() if rgdal does not work
library(rgdal)
library(tidyverse)
# check ogr drivers to see if GeoJSON is loaded:
# ogrDrivers()
......@@ -20,16 +21,24 @@ distritos <- readOGR("data/original/shapes/distritos.valencia.wgs84.geojson")
# proj4string(menores) # check CRS
# points
airbnb <- read_csv("data/output/190302_viviendas-turisticas-comunidad-valenciana_valencia_geocoded.csv")
summary(airbnb)
# airbnb <- read_csv("data/output/190302_viviendas-turisticas-comunidad-valenciana_valencia_geocoded_barrio-distrito.csv")
# summary(airbnb)
# airbnb <- airbnb %>% filter(!is.na(barrio))
# airbnb <- read_csv("data/output/190302_viviendas-turisticas-comunidad-valenciana_valencia_por-geocodificar_geocoded-photon2_por-geocodificar.csv")
# airbnb <- read_csv("data/output/190302_viviendas-turisticas-comunidad-valenciana_valencia_por-geocodificar_geocoded-photon2.csv")
airbnb <- read_csv("data/output/190302_viviendas-turisticas-comunidad-valenciana_valencia_geocoded-photon3.csv")
airbnb$id.row <- rownames(airbnb)
## Get long and lat from your data.frame. Make sure that the order is in lon/lat.
# source: https://stackoverflow.com/questions/29736577/how-to-convert-data-frame-to-spatial-coordinates#29736844
xy <- airbnb[,c("lon","lat")]
# removes NA values
airbnb <- airbnb[!is.na(airbnb$lon),]
airbnb.temp <- airbnb[!is.na(airbnb$lon),]
xy <- xy[!is.na(xy$lon),]
airbnbSp <- SpatialPointsDataFrame(coords = xy, data = airbnb, proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))
# creates spatial points data frame
airbnbSp <- SpatialPointsDataFrame(coords = xy, data = airbnb.temp, proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))
# class(airbnbSp)
# proj4string(airbnbSp)
......@@ -52,21 +61,49 @@ airbnbSp$coddistrit <- countDistritos$coddistrit
# Where are those points without barrio
library(ggmap)
qmplot(longitude, latitude, data = airbnb[is.na(airbnbSp$barrio =="no location"),], maptype = "toner-lite",
qmplot(lon, lat, data = airbnb[is.na(airbnbSp$barrio =="no location"),], maptype = "toner-lite",
color = I("red"),alpha = I(.2)) + labs(title= "Points without barrio" )
qmplot(longitude, latitude, data = airbnb, maptype = "toner-lite",
qmplot(lon, lat, data = airbnb, maptype = "toner-lite",
color = I("red"),alpha = I(.2)) + labs(title= "Points without barrio" )
airbnb <- as.data.frame(airbnbSp) # convert spatial data to regular data frame
airbnb.temp <- as.data.frame(airbnbSp) # convert spatial data to regular data frame
# removes duplicated columns with lat and long
drops <- c("lat.1","lon.1")
airbnb <- airbnb[ , !(names(airbnb) %in% drops)]
airbnb.temp <- airbnb.temp[ , !(names(airbnb.temp) %in% drops)]
airbnb <- left_join(airbnb,select(airbnb.temp,Signatura,barrio,distrito,coddistbar,coddistrit,id.row),by="id.row")
# Some points will be outside polygons and have Barrio variable fixed
airbnb[is.na(airbnbSp$barrio),]$name
# There are n points that have no Barrio assigned
length(airbnb[is.na(airbnbSp$barrio),]$name)
# table(airbnb$barrio)
# table(airbnb$distrito)
ggplot() +
geom_polygon(data = municipios,
aes(x = long, y = lat, group = group),
color = "grey", fill="white", size = 0.1) +
geom_polygon(data = barrios,
aes(x = long, y = lat, group = group),
color = "grey", fill="white", size = 0.5) +
geom_point(data= airbnb,
aes(x=lon, y=lat),
color=distrito,alpha=0.9,size = 0.1) +
# coord_fixed(xlim= c(-0.5, -0.2),ylim=c(39.0,39.75),ratio=1.3 )
coord_fixed(xlim= c(-0.49, -0.3),ylim=c(39.40,39.65),ratio=1.3 ) +
# theme_nothing(legend = TRUE) +
theme_minimal(base_family = "Roboto Condensed", base_size = 12) +
theme(
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
panel.background = element_rect(fill="#EEEEFF",color = "grey",size = 0.25),
legend.position = "top"
) +
labs(title=paste("VUT en Valencia", sep = "")) +
guides(colour = guide_legend(override.aes = list(size=3)))
# library(dplyr)
# airbnb$barrio <- lapply(airbnb$barrio, as.character)
......@@ -83,4 +120,4 @@ length(airbnb[is.na(airbnbSp$barrio),]$name)
# write.csv(airbnb, file = "data/output/vut-donostia/censo-viviendas-turisticas-donostia-180301_barrio-umenor.csv", row.names = FALSE)
# write.csv(airbnb, file = "data/output/vut-donostia/censo-viviendas-turisticas-donostia-20180914_barrio-umenor.csv", row.names = FALSE)
# write.csv(airbnb, file = "data/output/180604_listings-airbnb-donostia_datahippo_with-last-review-20180912-reviewed_barrio-umenor.csv", row.names = FALSE)
write.csv(airbnb, file = "data/output/190302_viviendas-turisticas-comunidad-valenciana_valencia_geocoded_barrio-distrito.csv", row.names = FALSE)
write.csv(airbnb, file = "data/output/190302_viviendas-turisticas-comunidad-valenciana_valencia_geocoded-photon3_barrio-distrito.csv", row.names = FALSE)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment