Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Efecto Airbnb
Efecto Airbnb Valencia
Commits
5f267803
Commit
5f267803
authored
Apr 22, 2019
by
numeroteca
Browse files
create interactive and better static with distritos shape, valencia ratio, with tmap
parent
2af6cba2
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
analysis/airbnb-analisis.R
View file @
5f267803
...
...
@@ -16,6 +16,7 @@ library(ggmap) #for theme nothing
library
(
reshape
)
library
(
gridExtra
)
library
(
gsubfn
)
# select text in the parenthesis with regex
library
(
spdplyr
)
#easier to dpplyr with spatialpolygons
# settings ---------
# emulating ggplot color palette https://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette
...
...
@@ -297,15 +298,16 @@ ggplot(aes(x = reorder(barrio, ratio2019_listings), y = ratio2019_listings)) + #
dev.off
()
# Ratio anuncios por viviendas en barrios. Barras. Top 15-------
png
(
filename
=
"images/airbnb/ratio-listings-airbnb-anuncios-barrios-valencia-201902_top15.png"
,
width
=
600
,
height
=
600
)
png
(
filename
=
"images/airbnb/ratio-listings-airbnb-anuncios-barrios-valencia-201902_top15
-blues
.png"
,
width
=
600
,
height
=
600
)
por_barrios
%>%
filter
(
!
is.na
(
ratio2019_listings
))
%>%
head
(
15
)
%>%
ggplot
(
aes
(
x
=
reorder
(
barrio
,
ratio2019_listings
),
y
=
ratio2019_listings
))
+
#order by Value or by -pos_ratio2019
geom_col
(
position
=
"dodge"
)
+
geom_col
(
position
=
"dodge"
,
aes
(
fill
=
ratio2019_listings
)
)
+
# scale_y_continuous(limits = c(0,8.5), expand = c(0,0)) +
scale_fill_gradient
(
low
=
"#ededed"
,
high
=
"#0cb2ff"
)
+
theme_minimal
(
base_family
=
"Roboto Condensed"
,
base_size
=
14
)
+
theme
(
panel.grid.minor.y
=
element_blank
(),
panel.grid.major.y
=
element_blank
(),
legend.position
=
"
bottom
"
legend.position
=
"
none
"
)
+
labs
(
title
=
"Presencia de Airbnb en barrios. Top15. Febrero 2019. Valencia"
,
subtitle
=
"Ratio de anuncios de Airbnb por cada 100 viviendas"
,
...
...
@@ -340,16 +342,17 @@ ggplot(aes(x = reorder(barrio, ratio2019_room_type), y = ratio2019_room_type)) +
coord_flip
()
dev.off
()
# Ratio anuncios pisos completos por viviendas completas en barrios. Barras. Top15
png
(
filename
=
"images/airbnb/ratio-airbnb-viviendas-completas-barrios-valencia-201902_top15.png"
,
width
=
600
,
height
=
600
)
# Ratio anuncios pisos completos por viviendas completas en barrios. Barras. Top15
-----
png
(
filename
=
"images/airbnb/ratio-airbnb-viviendas-completas-barrios-valencia-201902_top15
-blues
.png"
,
width
=
600
,
height
=
600
)
por_barrios.room_type
%>%
filter
(
room_type
==
"Vivienda completa"
)
%>%
filter
(
!
is.na
(
ratio2019_room_type
))
%>%
head
(
15
)
%>%
ggplot
(
aes
(
x
=
reorder
(
barrio
,
ratio2019_room_type
),
y
=
ratio2019_room_type
))
+
#order by Value or by -pos_ratio2019
geom_col
(
position
=
"dodge"
)
+
geom_col
(
position
=
"dodge"
,
aes
(
fill
=
ratio2019_room_type
))
+
scale_fill_gradient
(
low
=
"#ededed"
,
high
=
"#44c0fa"
)
+
# scale_y_continuous(limits = c(0,8.5), expand = c(0,0)) +
theme_minimal
(
base_family
=
"Roboto Condensed"
,
base_size
=
14
)
+
theme
(
panel.grid.minor.y
=
element_blank
(),
panel.grid.major.y
=
element_blank
(),
legend.position
=
"
bottom
"
legend.position
=
"
none
"
)
+
labs
(
title
=
"Presencia de Airbnb en barrios. Top15. Febrero 2019. Valencia"
,
subtitle
=
"Ratio de anuncios de viviendas completas en Airbnb por cada 100 viviendas"
,
...
...
@@ -358,7 +361,7 @@ por_barrios.room_type %>% filter( room_type == "Vivienda completa") %>% filter(!
caption
=
"Datos: InsideAirbnb. Gráfico: lab.montera34.com/airbnb"
)
+
geom_text
(
aes
(
label
=
ratio2019_room_type
),
position
=
position_dodge
(
width
=
1
),
hjust
=
-0.1
,
size
=
3
,
color
=
"#777777"
)
+
size
=
4
,
color
=
"#777777"
)
+
coord_flip
()
dev.off
()
...
...
@@ -554,16 +557,24 @@ tm_shape(barrios) +
# tmap Ratio anuncios / 100 viviendas ----------------
breaks.ratio
<-
c
(
0
,
1
,
2
,
4
,
6
,
8
,
10
,
12
,
14
,
16
)
# to select which labels are displayed
barrios_select
<-
barrios
%>%
filter
(
ratio2019_listings
>
3
)
png
(
filename
=
"images/airbnb/mapa-coropletas-ratio-anuncios-100viv-valencia-201902.png"
,
width
=
500
,
height
=
700
)
tm_shape
(
barrios
)
+
tm_polygons
(
col
=
"ratio2019_listings"
,
palette
=
colores
,
breaks
=
breaks.ratio
,
title
=
",
title
=
"
"
,
border.alpha
=
1
,
lwd
=
0.7
,
textNA
=
"sin anuncios"
)
+
# to display labels on top
# tm_shape(barrios_select) +
# tm_text("nombre", size = 0.8, col = "black" ) +
# tm_shape(distritos) +
# tm_borders(lwd=0.9, col = "black") +
tm_shape
(
municipios
)
+
tm_borders(lwd=0.1, col = "
black
") +
tm_borders
(
lwd
=
0.1
,
col
=
"black"
)
+
tm_layout
(
between.margin
=
5
,
frame
=
FALSE
,
fontfamily
=
"Roboto Condensed"
,
main.title
=
"Anuncios airbnb por 100 domicilios"
,
...
...
@@ -582,24 +593,108 @@ tm_shape(barrios) +
)
dev.off
()
# Ratio anuncios vivienda completa / 100 viviendas mapa estático------------------
# Ratio anuncios vivienda completa / 100 viviendas ------------------
# selects only few variables
airbnb
<-
airbnb201902
%>%
select
(
longitude
,
latitude
,
room_type
)
png(filename="
images
/
airbnb
/
mapa
-
coropletas
-
ratio
-
anuncios
-
vivcompletas
-100
viv
-
valencia
-201902
.png
",width = 500,height = 700)
tm_shape(barrios) +
tm_polygons(col="
ratio2018_room_type
",
# creates spatialpointsdataframe of airbnb listings
coordinates
(
airbnb
)
<-
~
longitude
+
latitude
# to select which labels are displayed
barrios_select
<-
barrios
%>%
filter
(
ratio2018_room_type
>
1
)
distritos_select
<-
distritos
%>%
filter
(
nombre
==
"CIUTAT VELLA"
|
nombre
==
"ALGIROS"
)
#| nombre == "POBLATS MARITIMS"
png
(
filename
=
"images/airbnb/mapa-coropletas-ratio-anuncios-vivcompletas-100viv-valencia-201902.png"
,
width
=
2500
,
height
=
2700
)
tm_polygons
(
col
=
"ratio2018_room_type"
,
palette
=
colores
,
breaks
=
breaks.ratio
,
title
=
""
,
border.alpha
=
1
,
lwd
=
0.7
,
textNA
=
"sin anuncios"
)
+
# tm_shape(barrios_select) +
tm_shape
(
barrios
)
+
tm_text
(
"nombre"
,
size
=
1.2
,
col
=
"black"
,
remove.overlap
=
TRUE
)
+
# airbnb listings
tm_shape
(
airbnb
)
+
tm_dots
(
alpha
=
0.3
,
size
=
0.06
)
+
#col = "room_type",
tm_shape
(
distritos
)
+
tm_borders
(
lwd
=
0.9
,
col
=
"black"
)
+
# nombre de distritos
# tm_shape(distritos) +
# tm_text("nombre", size = 1.5, col = "#000099", just="bottom") + #, just="left"
tm_shape
(
municipios
)
+
tm_borders
(
lwd
=
0.1
,
col
=
"black"
)
+
tm_layout
(
between.margin
=
5
,
frame
=
FALSE
,
fontfamily
=
"Roboto Condensed"
,
main.title
=
"Anuncios viviendas completas por 100 domicilios"
,
main.title.size
=
1.1
,
main.title.fontface
=
"bold"
,
title
=
""
,
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
,
legend.format
=
list
(
text.separator
=
"-"
)
)
dev.off
()
# Ratio anuncios vivienda completa / 100 viviendas mapa interactivo------------------
# selects only few variables
airbnb
<-
airbnb201902
%>%
select
(
longitude
,
latitude
,
room_type
)
# creates spatialpointsdataframe of airbnb listings
coordinates
(
airbnb
)
<-
~
longitude
+
latitude
# to select which labels are displayed
barrios_select
<-
barrios
%>%
filter
(
ratio2018_room_type
>
2
)
distritos_select
<-
distritos
%>%
filter
(
nombre
==
"CIUTAT VELLA"
|
nombre
==
"ALGIROS"
)
#| nombre == "POBLATS MARITIMS"
interactive_map
<-
tm_shape
(
barrios
)
+
tm_polygons
(
col
=
"ratio2018_room_type"
,
palette
=
colores
,
breaks
=
breaks.ratio
,
title = "",
title
=
"
anuncios airbnb / 100 viviendas
"
,
border.alpha
=
1
,
lwd
=
0.7
,
textNA="
sin
anuncios
") +
textNA
=
"sin anuncios"
,
id
=
"nombre"
,
# popup.vars=TRUE
# popup.vars=c("count", "ratio2018_room_type","seabstienen"), #selects data in popup
popup.vars
=
c
(
# "barrio" = "nombre",
"ratio anuncios Airbnb / 100 viviendas"
=
"ratio2019_listings"
,
"anuncios Airbnb"
=
"suma"
,
"anuncios viviendas Airbnb"
=
"count"
,
"ratio anuncios vivienda / 100 viviendas"
=
"ratio2018_room_type"
,
"viviendas existentes"
=
"Total"
,
"viviendas principales"
=
"Principales"
)
)
+
# nombre barrios
tm_shape
(
barrios_select
)
+
# tm_shape(barrios) +
tm_text
(
"nombre"
,
size
=
1.3
,
col
=
"black"
,
remove.overlap
=
TRUE
,
shadow
=
TRUE
)
+
# airbnb listings
tm_shape
(
airbnb
)
+
# tm_dots(alpha=0.3,size=0.06) + #col = "room_type",
tm_dots
(
alpha
=
0.3
,
size
=
0.0006
,
popup.vars
=
FALSE
)
+
#col = "room_type",
tm_shape
(
distritos
)
+
tm_borders
(
lwd
=
0.9
,
col
=
"black"
)
+
# nombre de distritos
# tm_shape(distritos) +
# tm_text("nombre", size = 1.5, col = "#000099", just="bottom") + #, just="left"
tm_shape
(
municipios
)
+
tm_borders
(
lwd
=
0.1
,
col
=
"black"
)
+
tm_layout
(
between.margin
=
5
,
frame
=
FALSE
,
fontfamily
=
"Roboto Condensed"
,
main.title = "
Anuncios
viviendas
completa
airbnb
por
100
domicilios
",
main.title
=
"Anuncios viviendas completa
s
por 100 domicilios"
,
main.title.size
=
1.1
,
main.title.fontface
=
"bold"
,
fontface
=
"bold"
,
title
=
""
,
title.size
=
2
,
title.position
=
c
(
"center"
,
"top"
),
...
...
@@ -610,8 +705,13 @@ tm_shape(barrios) +
legend.bg.color
=
"white"
,
legend.bg.alpha
=
0.8
,
legend.format
=
list
(
text.separator
=
"-"
)
)
dev.off()
)
+
# zoom view to district selected
tm_view
(
bbox
=
barrios
%>%
filter
(
nombre
==
"LA PETXINA"
|
nombre
==
"LA MALVA-ROSA"
|
nombre
==
"NA ROVELLA"
))
tmap_save
(
interactive_map
,
"/home/numeroteca/sites/airbnb/valencia/output/html/ratio-vivcompletaairbnb-x-viv-coropletas-valencia-201902.html"
)
# Plazas de Airbnb por habitante -------------------------------
# agrupa datos añadiendo código de distrito
...
...
images/airbnb/hosts/10top-hosts-vlc-201902-airbnb.png
0 → 100644
View file @
5f267803
106 KB
images/airbnb/mapa-coropletas-ratio-anuncios-vivcompletas-100viv-valencia-201902.png
View replaced file @
2af6cba2
View file @
5f267803
72.1 KB
|
W:
|
H:
75.4 KB
|
W:
|
H:
2-up
Swipe
Onion skin
images/airbnb/ratio-airbnb-viviendas-completas-barrios-valencia-201902_top15-blues.png
View replaced file @
2af6cba2
View file @
5f267803
33.1 KB
|
W:
|
H:
30.6 KB
|
W:
|
H:
2-up
Swipe
Onion skin
output/html/ratio-vivcompletaairbnb-x-viv-coropletas-valencia-201902.html
0 → 100644
View file @
5f267803
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment