Commit b9c24edb authored by numeroteca's avatar numeroteca

add barrios word title and desc. analysis for barrios

parent 2cf2dcdd
......@@ -6,8 +6,7 @@ library(tidyverse)
# load data ----
local_activo <- read.delim("tmp/listings-palabras.csv",sep = ",")
# Transform data
# Transform data para distritos ------------------------------------------------------------
distritos.count <- local_activo %>% group_by(neighbourhood_group_cleansed) %>% summarise(total = n() )
playa.desc <- local_activo %>% group_by(neighbourhood_group_cleansed,descripcion.tiene.playa) %>% summarise(count = n() ) %>% ungroup()
centro.desc <- local_activo %>% group_by(neighbourhood_group_cleansed,descripcion.tiene.centro) %>% summarise(count = n() ) %>% ungroup()
......@@ -30,13 +29,36 @@ distritos.count$centro.desc.p <- round(100* distritos.count$anuncios.centro.desc
distritos.count$playa.tit.p <- round(100* distritos.count$anuncios.playa.tit / distritos.count$total, digits=1)
distritos.count$centro.tit.p <- round(100* distritos.count$anuncios.centro.tit / distritos.count$total, digits=1)
distritos.count %>% filter(!is.na(playa.tit.p)) %>%
ggplot(aes(reorder(distrito,playa.tit.p),playa.tit.p)) +
# Transform data para barrios ------------------------------------------------------------
barrios.count <- local_activo %>% group_by(neighbourhood_cleansed) %>% summarise(total = n() )
playa.desc <- local_activo %>% group_by(neighbourhood_cleansed,descripcion.tiene.playa) %>% summarise(count = n() ) %>% ungroup()
centro.desc <- local_activo %>% group_by(neighbourhood_cleansed,descripcion.tiene.centro) %>% summarise(count = n() ) %>% ungroup()
playa.tit <- local_activo %>% group_by(neighbourhood_cleansed,titulo.tiene.playa) %>% summarise(count = n() ) %>% ungroup()
centro.tit <- local_activo %>% group_by(neighbourhood_cleansed,titulo.tiene.centro) %>% summarise(count = n() ) %>% ungroup()
names(barrios.count) <- c("barrio","total")
names(playa.desc) <- c("barrio","tiene","anuncios.playa.desc")
names(centro.desc) <- c("barrio","tiene","anuncios.centro.desc")
names(playa.tit) <- c("barrio","tiene","anuncios.playa.tit")
names(centro.tit) <- c("barrio","tiene","anuncios.centro.tit")
barrios.count <- full_join(barrios.count, playa.desc %>% filter(tiene==TRUE) %>% select(barrio,anuncios.playa.desc),by = "barrio")
barrios.count <- full_join(barrios.count, centro.desc %>% filter(tiene==TRUE) %>% select(barrio,anuncios.centro.desc),by = "barrio")
barrios.count <- full_join(barrios.count, playa.tit %>% filter(tiene==TRUE) %>% select(barrio,anuncios.playa.tit),by = "barrio")
barrios.count <- full_join(barrios.count, centro.tit %>% filter(tiene==TRUE) %>% select(barrio,anuncios.centro.tit),by = "barrio")
barrios.count$playa.desc.p <- round(100* barrios.count$anuncios.playa.desc / barrios.count$total, digits=1)
barrios.count$centro.desc.p <- round(100* barrios.count$anuncios.centro.desc/ barrios.count$total, digits=1)
barrios.count$playa.tit.p <- round(100* barrios.count$anuncios.playa.tit / barrios.count$total, digits=1)
barrios.count$centro.tit.p <- round(100* barrios.count$anuncios.centro.tit / barrios.count$total, digits=1)
barrios.count %>% filter(!is.na(playa.tit.p)) %>%
ggplot(aes(reorder(barrio,playa.tit.p),playa.tit.p)) +
geom_col() +
coord_flip() +
labs(title="Porcentaje anuncios lleva la palabra playa en título",
labs(title="Porcentaje anuncios lleva la 'palabra' playa en título",
# subtitle = paste("Airbnb en ", local_activo_name, ". ",fecha_simple,".",sep=""),
x="distrito",
x="barrio",
y="porcentaje anuncios",
caption = caption_1) +
theme_minimal(base_family = "Roboto Condensed", base_size = 14) +
......@@ -62,60 +84,119 @@ library(htmlwidgets)
# para sprintf
library(htmltools)
# shapes
# barrios <- readOGR("data/original/shapes/barrios.valencia.wgs84.geojson")
barrios <- readOGR("data/original/shapes/barrios.valencia.wgs84.geojson")
distritos <- readOGR("data/original/shapes/distritos.valencia.wgs84.geojson")
# municipios <- distritos
# municipios <- readOGR("data/original/shapes/municipios.provincia.valencia.geojson")
municipios <- readOGR("data/original/shapes/municipios.provincia.valencia.geojson")
# Define paleta de color
palette1 <- c("#4292c6","#6baed6","#9ecae1","#fee5d9")
colores <- c("#eff3ff", "#084594")
# Añade datos a contornos de las secciones censales --------------------------------------------------------------
# Añade datos a contornos--------------------------------------------------------------
distritos@data <- full_join(distritos@data, distritos.count,by =c("nombre" = "distrito"))
barrios@data <- full_join(barrios@data, barrios.count,by =c("nombre" = "barrio"))
# mapa -----------------
# mapa para distritos -----------------
png(filename="images/airbnb/palabras/playa-centro-mapa-distritos-descripcion.png",width = 600,height = 600)
tm_shape(distritos) +
tm_polygons(col=c("playa.desc.p","centro.desc.p"),
palette = colores,
# breaks = breaks,
title = "% anuncios",
border.alpha = 1, lwd = 0.7) +
# tm_shape(municipios) +
# tm_borders(lwd=2, col = "black", alpha = .5) +
tm_shape(municipios) +
tm_borders(lwd=0.1, col = "black") +
tm_layout(between.margin = 5, frame = FALSE,
fontfamily = "Roboto Condensed",
main.title = "% de anuncios con la palabra en descripción...",
main.title.size = 2.2,
title = c("playa","centro") ,
title.size = 2,
title.position = c("center","top"),
title.fontface = "bold",
legend.title.size = 1,
legend.text.size = 0.6,
legend.text.size = 1,
legend.position = c("left","bottom"),
legend.bg.color = "white",
# legend.digits = 5,
legend.bg.alpha = 1
legend.bg.alpha = 0.8
)
dev.off()
png(filename="images/airbnb/palabras/playa-centro-mapa-distritos-titulo.png",width = 600,height = 600)
tm_shape(distritos) +
tm_polygons(col=c("playa.tit.p","centro.tit.p"),
palette = colores,
# breaks = breaks,
title = "% anuncios",
border.alpha = 1, lwd = 0.7) +
# tm_shape(municipios) +
# tm_borders(lwd=2, col = "black", alpha = .5) +
tm_shape(municipios) +
tm_borders(lwd=0.1, col = "black") +
tm_layout(between.margin = 5, frame = FALSE,
fontfamily = "Roboto Condensed",
main.title = "% de anuncios con la palabra en título...",
main.title.size = 2.2,
title = c("playa","centro") ,
title.size = 2,
title.position = c("center","top"),
title.fontface = "bold",
legend.title.size = 1,
legend.text.size = 1,
legend.position = c("left","bottom"),
legend.bg.color = "white",
legend.bg.alpha = 0.8
)
dev.off()
# mapa para barrios -----------------
png(filename="images/airbnb/palabras/playa-centro-mapa-barrios-descripcion.png",width = 600,height = 600)
tm_shape(barrios) +
tm_polygons(col=c("playa.desc.p","centro.desc.p"),
palette = colores,
# breaks = breaks,
title = "% anuncios",
border.alpha = 1, lwd = 0.7) +
tm_shape(municipios) +
tm_borders(lwd=0.1, col = "black") +
tm_layout(between.margin = 5, frame = FALSE,
fontfamily = "Roboto Condensed",
main.title = "% de anuncios con la palabra en descripción...",
main.title.size = 2.2,
title = c("playa","centro") ,
title.size = 2,
title.position = c("center","top"),
title.fontface = "bold",
legend.title.size = 1,
legend.text.size = 1,
legend.position = c("left","bottom"),
legend.bg.color = "white",
legend.bg.alpha = 0.8
)
dev.off()
png(filename="images/airbnb/palabras/playa-centro-mapa-barrios-titulo.png",width = 600,height = 600)
tm_shape(barrios) +
tm_polygons(col=c("playa.tit.p","centro.tit.p"),
palette = colores,
# breaks = breaks,
title = "% anuncios",
border.alpha = 1, lwd = 0.7) +
tm_shape(municipios) +
tm_borders(lwd=0.1, col = "black") +
tm_layout(between.margin = 5, frame = FALSE,
fontfamily = "Roboto Condensed",
main.title = "% de anuncios con la palabra en título...",
main.title.size = 2.2,
title = c("playa","centro") ,
title.size = 2,
title.position = c("center","top"),
title.fontface = "bold",
legend.title.size = 1,
legend.text.size = 0.6,
legend.text.size = 1,
legend.position = c("left","bottom"),
legend.bg.color = "white",
# legend.digits = 5,
legend.bg.alpha = 1
legend.bg.alpha = 0.8
)
dev.off()
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