R's statistical and visualisation capabilities make it ideal for real estate market analysis. This tutorial uses httr and ggplot2 to analyse market data across a set of ZIP codes.
Fetching Data
library(httr)
library(jsonlite)
library(dplyr)
library(ggplot2)
API_KEY <- Sys.getenv("ZIPMARKET_KEY")
BASE <- "https://zipmarketdata.com"
get_market_stats <- function(zip_code) {
resp <- GET(
paste0(BASE, "/market-stats"),
query = list(zip_code = zip_code),
add_headers("x-rapidapi-proxy-secret" = API_KEY)
)
fromJSON(content(resp, "text", encoding = "UTF-8"))
}
zips <- c("78701","30301","85001","37201","80201")
stats <- bind_rows(lapply(zips, get_market_stats))
Visualising Yield vs Price
ggplot(stats, aes(x = median_sale_price, y = yoy_price_change,
label = zip_code, colour = market_temperature)) +
geom_point(size = 4) +
geom_text(vjust = -0.8, size = 3) +
scale_x_continuous(labels = scales::dollar) +
labs(title = "Price vs. YoY Change by ZIP Code",
x = "Median Sale Price", y = "YoY Price Change (%)",
colour = "Market Temperature") +
theme_minimal()