Airbnb European Snapshot

R
ggplot2
Parameterized HTML dashboards for various cities
Published

April 11, 2023

Starting with the datasets

The original datasets were all based on city and listing type (weekday or weekend). I needed to clean the data a bit and wrangle them into one main dataset. The parameter of interest was city.

Behind the scenes
library(tidyverse)
library(ggplot2)
library(dplyr)
library(purrr)
library(data.table)
library(gsubfn)
library(tidyr)
library(flexdashboard)


files <- dir(pattern = "*.csv")
file.list <- sapply(files, read.csv, simplify=FALSE)
airbnb <- rbindlist(file.list, idcol="city")[, city := gsub("(.*)[_]([^.]+)[.].*", "\\1 \\2",city)]
airbnb<-separate(airbnb, city, into = c("city", "type"), sep = " (?=[^ ]+$)")
write.csv(airbnb, "airbnb.csv", row.names=FALSE)

Dashboard pieces

Next up was to subset the data based on city and create a color palette for the dashboard based on Airbnb brand colors. Then the various plots used in the dashboard were created.

Behind the scenes
airbnb_subset <- airbnb %>%
  filter(city == params$city)

cbPalette <- c("#5AB2FF", "#00A699", "#FFE25A", "#845AFF", "#FC642D", "#FF5A5F")

bedplot<-airbnb_subset %>%
  ggplot(aes(bedrooms, fill=type)) +
    geom_bar(stat="count",position="dodge")+
    theme_minimal()+
    theme(legend.position="bottom")+ 
    labs(fill="", x = "Number of Bedrooms", y = "")  +
    scale_fill_manual(values=cbPalette)


cleanplot<-airbnb_subset %>%
  ggplot(aes(cleanliness_rating, fill=room_type)) +
    geom_bar(stat="count",position="dodge")+
    theme_minimal()+
    theme(legend.position="bottom")+ 
    labs(fill="", x = "Cleanliness Rating", y = "")  +
    scale_fill_manual(values=cbPalette)

dist<-airbnb_subset %>%
  filter(realSum<4000) %>%
  ggplot(aes(x=metro_dist, y=realSum, color=type)) +
    geom_point(alpha=.5, size=2)+
    theme_minimal()+
    theme(legend.position="bottom")+ 
    labs(color="", x = "Distance from City Center", y = "Total Price") +
    scale_color_manual(values=cbPalette)

Dashboard layout

Finally the final layout was created to show the valueboxes and the plots that were layed out above.

Behind the scenes
articles <- nrow(airbnb_subset)
valueBox(articles, icon = "fa-home")

super <- nrow(airbnb_subset %>% filter(host_is_superhost == "True"))
valueBox(super, icon = "fa-user")

avgprice <- round(mean(airbnb_subset$realSum),digits = 0)
valueBox(avgprice, icon = "fa-coins")

avgprice <- round(mean(airbnb_subset$guest_satisfaction_overall),digits = 0)
valueBox(avgprice, icon = "fa-star")

bedplot

cleanplot

dist

Rendering code

In a separate render.r file the following code was run, resulting in the various HTML dashboards.

Behind the scenes
city <- unique(airbnb$city)

reports <- tibble(
  output_file = stringr::str_c("output/", city, "-airbnb.html"),
  params = map(city, ~list(city = .))
)

reports %>%
  pwalk(rmarkdown::render, input = "airbnb/parameter.qmd")

Final HTML Dashboards

Here are the final HTML dashboards that are produced:

« Back to Projects