Commit 7ab52cc0 authored by numeroteca's avatar numeroteca

script para analizar palabras en distritos

parent adc00b0b
# palabras
# Instala y carga librerías ----
library(tidyverse)
# load data ----
local_activo <- read.delim("tmp/listings-palabras.csv",sep = ",")
# Transform data
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()
playa.tit <- local_activo %>% group_by(neighbourhood_group_cleansed,titulo.tiene.playa) %>% summarise(count = n() ) %>% ungroup()
centro.tit <- local_activo %>% group_by(neighbourhood_group_cleansed,titulo.tiene.centro) %>% summarise(count = n() ) %>% ungroup()
names(distritos.count) <- c("distrito","total")
names(playa.desc) <- c("distrito","tiene","anuncios.playa.desc")
names(centro.desc) <- c("distrito","tiene","anuncios.centro.desc")
names(playa.tit) <- c("distrito","tiene","anuncios.playa.tit")
names(centro.tit) <- c("distrito","tiene","anuncios.centro.tit")
distritos.count <- full_join(distritos.count, playa.desc %>% filter(tiene==TRUE) %>% select(distrito,anuncios.playa.desc),by = "distrito")
distritos.count <- full_join(distritos.count, centro.desc %>% filter(tiene==TRUE) %>% select(distrito,anuncios.centro.desc),by = "distrito")
distritos.count <- full_join(distritos.count, playa.tit %>% filter(tiene==TRUE) %>% select(distrito,anuncios.playa.tit),by = "distrito")
distritos.count <- full_join(distritos.count, centro.tit %>% filter(tiene==TRUE) %>% select(distrito,anuncios.centro.tit),by = "distrito")
distritos.count$playa.desc.p <- round(100* distritos.count$anuncios.playa.desc / distritos.count$total, digits=1)
distritos.count$centro.desc.p <- round(100* distritos.count$anuncios.centro.desc/ distritos.count$total, digits=1)
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)) +
geom_col() +
coord_flip() +
labs(title="Porcentaje anuncios lleva la palabra playa en título",
# subtitle = paste("Airbnb en ", local_activo_name, ". ",fecha_simple,".",sep=""),
x="distrito",
y="porcentaje anuncios",
caption = caption_1) +
theme_minimal(base_family = "Roboto Condensed", base_size = 14) +
theme(
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_blank(),
legend.position = "top"
)
# maps ------------------------------
# read shapes
library(rgdal)
library(ggmap) #for theme nothing
library(reshape)
library(gridExtra)
library(gsubfn) # select text in the parenthesis with regex
# Mapas de coropletas
library(tmap)
library("tmaptools")
# to save interactive maps
library(htmlwidgets)
# para sprintf
library(htmltools)
# shapes
# 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")
# Define paleta de color
palette1 <- c("#4292c6","#6baed6","#9ecae1","#fee5d9")
colores <- c("#eff3ff", "#084594")
# Añade datos a contornos de las secciones censales --------------------------------------------------------------
distritos@data <- full_join(distritos@data, distritos.count,by =c("nombre" = "distrito"))
# mapa -----------------
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_layout(between.margin = 5, frame = FALSE,
fontfamily = "Roboto Condensed",
main.title = "% de anuncios con la palabra en descripción...",
title = c("playa","centro") ,
title.fontface = "bold",
legend.title.size = 1,
legend.text.size = 0.6,
legend.position = c("left","bottom"),
legend.bg.color = "white",
# legend.digits = 5,
legend.bg.alpha = 1
)
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_layout(between.margin = 5, frame = FALSE,
fontfamily = "Roboto Condensed",
main.title = "% de anuncios con la palabra en título...",
title = c("playa","centro") ,
title.fontface = "bold",
legend.title.size = 1,
legend.text.size = 0.6,
legend.position = c("left","bottom"),
legend.bg.color = "white",
# legend.digits = 5,
legend.bg.alpha = 1
)
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