OkBublewrap

지하철 아파트 가격 상관관계 본문

R/프로젝트

지하철 아파트 가격 상관관계

옥뽁뽁 2021. 7. 19. 00:19

<데이터 정보>
지하철역정보 : 부산광역시 공공데이터포탈 #부산교통공사_도시철도 역정보_20201020.CSV
아파트 실거래가 : 국토교통부 실거래가 공개시스템 # 20210101~20210501

<패키지>

library(dplyr)
library(devtools)
library(ggmap) 
library(readxl)
library(ggplot2)
# csv 파일 
station <- read.csv("c:/Temp1/프로젝트/역정보.csv") 
View(station) 
str(station)

View(station)

# google API
googleAPIkey <- "*********" # 구글 API 등록키
register_google(googleAPIkey)
# geocpde() 함수로 station_code 값을 위도와 경도로 변환
station_code <- as.character(station$'역주소') 
station_code <- geocode(station_code) View(station_code)

변환된 위도, 경도

# 데이터 합치기 
station_final <- cbind(station, station_code) 
View(station_final) str(station_final)

View(station_final)

# 경성대*부경대역에 대한 필터링 
station_final <- filter(station_final, station_final$역명 == '경성대·부경대')
# 실거래가 파일 
apt_price <- read_excel("c:/Temp1/프로젝트/실거래가.xlsx") 
str(apt_price)

tibble[,5] [958 x 5] (S3: tbl_df/tbl/data.frame)
$ 시군구 : chr [1:958] "부산광역시 남구 감만동" "부산광역시 남구 감만동" "부산광역시 남구 감만동" "부산광역시 남구 감만동" ...
$ 번지 : chr [1:958] "225-2" "225-2" "225-2" "225-2" ...
$ 단지명 : chr [1:958] "감만현대1차" "감만현대1차" "감만현대1차" "감만현대1차" ...
$ 전용면적: chr [1:958] "59.92" "59.92" "59.92" "59.92" ...
$ 거래금액: chr [1:958] "14,350" "14,500" "15,500" "14,800" ...

# 면적이 str로 나왔는데 수치형 반올림자료로 구성 
apt_price$면적 <- round(as.numeric(apt_price$전용면적))
View(apt_price)

면적이 반올림된 데이터&nbsp;

# 쉼표 제거, 수치형으로 변환 
apt_price$거래금액 <- gsub(",", "", apt_price$거래금액) 
apt_price$거래금액 <- as.numeric(apt_price$거래금액) 

# 단지별 평균 구하기 
apt_m_price <- aggregate(거래금액 ~ 단지명, apt_price, mean)
View(apt_m_price)

쉼표제거된 거래금액, 아파트별 평균거래금액으로 표기

# 단지명이 중복된 행제거 
apt_price <- apt_price[!duplicated(apt_price$'단지명'),] 

# 데이터 합치기 
apt_data <- left_join(apt_price, apt_m_price, by = '단지명')
View(apt_data)

apt_data

# 필요한 변수명 선택 
apt_data <- apt_data %>% select(-"전용면적", -"거래금액.x") 
apt_data <- rename(apt_data, "거래금액" = "거래금액.y") 
View(apt_data)

apt_data(면적, 거래금액)

# 시군구 데이터 합치기 
apt_add <- paste(apt_data$시군구, apt_data$번지) %>% data.frame() 
head(apt_add)

1 부산광역시 남구 감만동 225-2
2 부산광역시 남구 감만동 233-1
3 부산광역시 남구 감만동 20-1
4 부산광역시 남구 감만동 73-212
5 부산광역시 남구 감만동 208-3
6 부산광역시 남구 감만동 44-151

# 주소로 변수명 지정 
apt_add <- rename(apt_add, "주소" = ".") 
View(apt_add) 
str(apt_add)

apt_add

# 좌표추가 데이터 
apt_fin <- as.character(apt_add$주소) %>% enc2utf8() %>% geocode() 

# 데이터 합치기
apt <- cbind(apt_data, apt_fin) 
View(apt) 
str(apt)

apt

# apt 필터링
apt <- filter(apt, apt$시군구 == '부산광역시 남구 대연동') 

# 시군구가 대연동인 아파트 필터링 
apt <- filter(apt, apt$면적 == 60) # 면적이 60인 아파트 필터링
# 남구 지도 가져오기 
namgu <- get_googlemap("namgu", maptype = "roadmap", zoom =15) 
ggmap(namgu)

ggmap(namgu)

# 지하철 위치 , 면적이 60인 아파트 가격
ggmap(namgu) + geom_point(station_final, mapping = aes(x = lon, y = lat), colour = 'black', size = 1) 
	+ geom_text(station_final, mapping = aes(label = 역명, vjust = -1)) 
    + geom_point(apt, mapping = aes(x = lon, y = lat)) 
    + geom_text(apt, mapping = aes(label = 단지명, vjust = -1)) 
    + geom_text(apt, mapping = aes(label = 거래금액, vjust = 1))

남구지도에 아파트가격 표시

역에서 제일 가까운 대연롯데캐슬은 70000, 거리가 먼 대우그린은 약 17000으로 가격이 낮은 것을 알 수 있다.

'R > 프로젝트' 카테고리의 다른 글

서울특별시 대기분석  (0) 2021.07.09
서울 특별시 공연장 분포표  (0) 2021.07.07