library(XML)
library(RCurl)
library(dplyr)
<- readRDS("apartment_key_datagokr.rds")
service_key <- vector("list", 12)
datlist
# combine the data in 2022
for (m in 1:12){
if (m < 10) {
<- paste0("20220", m)
dt else {
} <- paste0("2022", m)
dt
} <- paste0("http://openapi.molit.go.kr/OpenAPI_ToolInstallPackage/service/rest/RTMSOBJSvc/getRTMSDataSvcAptTradeDev?LAWD_CD=11110&DEAL_YMD=", dt, "&serviceKey=", service_key)
uri
<- xmlTreeParse(uri, useInternalNodes = TRUE, encoding = "UTF-8")
xml_doc <- xmlRoot(xml_doc)
root_node <- xmlToDataFrame(nodes = getNodeSet(root_node, '//item'))
xml_data
<- xml_data
datlist[[m]]
}
<- do.call('rbind', datlist) d
Apartment transactions in Korea via API provided by the Ministry of Land, Infrastructure, and Transport
R
API
apartment
Data preparation
I will plot the price
# million won
$price <- as.numeric(gsub('\\,', "", d$거래금액)) / 100
d$area_sq_meter <- as.numeric(d$전용면적) # q
d$area_category <- NA
d
for(i in 1:nrow(d)) {
<- d$area_sq_meter[i]
ar if(ar < 50){
$area_category[i] <- "<50"
d
}else if(ar >= 50 & ar < 80) {
$area_category[i] <- "50-80"
d
}else if(ar >= 80 & ar < 100) {
$area_category[i] <- "80-100"
d
}else if(ar >= 100) {
$area_category[i] <- ">100"
d
}
}
$area_category <- factor(d$area_category, levels=c("<50", "50-80", "80-100",">100"))
d
$levels <- as.numeric(d$층)
d
library(ggplot2)
|> as.data.frame() |>
d ggplot()+
geom_point(aes(area_category, price, color=levels)) +
labs(x=parse(text=paste0("Area~(m^2)")), y="Price (million won)", color=parse(text=paste0("Levels")))+
theme_bw()+
ggtitle("Apartment price in Jongno-gu, Seoul, 2022")
# ggsave("apt_price.png", width=3.4*1.5, height=2.7*1.5, units="in")