Resume where you left off
Online at https://diogoribeiro7.github.io/analytics-blog-jekyll/tutorials/2024/02/05/r-exploratory-analysis-housing/
Topics
Project setup
1
2
3
4
5
6
library(tidyverse)
library(lubridate)
library(scales)
housing <- read_csv("data/housing_portugal.csv")
glimpse(housing)
Key checks before modeling:
- Inspect missing values with
skimr::skim. - Validate coordinate reference systems if spatial joins are required.
- Record assumptions in an analysis log (see
/docs/analysis-playbook.md).
Feature engineering
1
2
3
4
5
6
7
housing <- housing %>%
mutate(
price_per_m2 = price_eur / floor_area_m2,
listing_month = floor_date(listing_date, "month"),
energy_rating = fct_explicit_na(energy_rating, "Unknown"),
is_new_build = if_else(construction_year > 2018, TRUE, FALSE)
)
Visualizing distributions
1
2
3
4
5
6
7
8
9
10
11
ggplot(housing, aes(price_per_m2, fill = property_type)) +
geom_histogram(binwidth = 250) +
scale_x_continuous(labels = label_dollar(prefix = "€")) +
facet_wrap(~property_type) +
labs(
title = "Distribution of price per square meter",
subtitle = "Segmented by property type",
x = "Price per m²",
y = "Count"
) +
theme_minimal(base_size = 14)
Communicating findings
- Central Lisbon apartments average €5,100/m² with a right-skewed tail.
- New builds exhibit a 15% premium relative to comparable resale properties.
- Energy ratings remain missing for 32% of listings—prioritize data enrichment.
Reproducibility checklist
- Render the R Markdown document with
targets::tar_make()to guarantee order. - Publish companion notebooks via Netlify or GitHub Pages with
quarto publish. - Pin package versions using
renv::snapshot()and commit the lockfile.
Download the analysis repository or launch the interactive Observable notebook to explore alternative visual encodings.
Your private highlights
Kept in this browser only and never sent anywhere. These are your notes, not comments. With text selected, Alt+Shift+H highlights it and Alt+Shift+N adds a note.
This browser is not letting the site keep data, so saving, progress and highlights are off.
Select a passage of the article to highlight it.
Your reading data
-
Observable notebook comparison
Review the Observable notebook to contrast R and JavaScript pipelines.
© 2024 Diogo Ribeiro. Text and figures under CC BY 4.0.
How to cite
Use the quick export buttons to save citations for reference managers or copy the formatted text directly.
Diogo Ribeiro (2024). R Exploratory Analysis of Urban Housing Markets. DataLog | Data Science & Research Theme. https://diogoribeiro7.github.io/analytics-blog-jekyll/tutorials/2024/02/05/r-exploratory-analysis-housing/.
BibTeX
RIS
EndNote
Open science & reproducibility badges
These badges highlight the transparency practices applied to this work. Hover or focus on each badge to learn more about the criteria.
- Open Data Dataset and code repository published with permissive license. Public repository, DOI issued, README with reproduction steps.
- Reproducible Workflow Containerized environment and automated tests provided. Continuous integration pipeline with reproducibility checks.
- Transparent Peer Review Peer review reports archived with DOI and linked to article. Open peer review statement and archived reports on Zenodo.
