房屋租赁信息
北上广深房屋租赁数据分析
北上广深四个一线城市,哪个城市的租房更加友好呢?城市各区域的租金是怎么分布的?离地铁口远近、房子大小、是否公寓房、精装简装、集中供暖等,租房时应该优先考虑哪些因素呢?
同时如何对带地理经纬度等信息进行可视化呢?
所以本项目获取了链家网北上广深四个城市的各三千条租房数据数据共有12000条进行实践探索
一、数据预处理
#设置工作路径
setwd("D:/LengPY")
#导入数据
data<- read.csv("housedata.csv",,encoding='UTF-8')
head(data)
X_id | bathroom_num | bedroom_num | bizcircle_name | city | dist | distance | frame_orientation | hall_num | house_tag | house_title | latitude | layout | longitude | m_url | rent_area | rent_price_listing | rent_price_unit | resblock_name | type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<chr> | <int> | <int> | <chr> | <chr> | <chr> | <int> | <chr> | <int> | <chr> | <chr> | <dbl> | <chr> | <dbl> | <chr> | <chr> | <chr> | <chr> | <chr> | <chr> | |
1 | 5c714363397be4c5251a3ded | 2 | 3 | 上地 | 北京 | 海淀 | NA | 南 北 | 2 | 精装 集中供暖 双卫生间 | 整租 · 上地西里二层三居 自住出租 随时入住采光好 无遮挡 | 40.03900 | 3室2厅2卫 | 116.3178 | https://m.lianjia.com/chuzu/bj/zufang/BJ2135934725586690048.html | 137 | 15000 | 元/月 | 上地西里 | 整租 |
2 | 5c7148e6397be4c5251a583d | 1 | 2 | 北大地 | 北京 | 丰台 | NA | 南 北 | 1 | 集中供暖 | 整租 · 丰台北大地电报局街家具家电齐全南北向两居 | 39.85666 | 2室1厅1卫 | 116.2923 | https://m.lianjia.com/chuzu/bj/zufang/BJ2101229402263126016.html | 57 | 4500 | 元/月 | 电报局街 | 整租 |
3 | 5c71321e397be4c5251a0b46 | 1 | 1 | 燕莎 | 北京 | 朝阳 | 788 | 北 | 1 | 近地铁 精装 集中供暖 | 整租 · 远洋新干线 1室1厅 10500元 | 39.96323 | 1室1厅1卫 | 116.4661 | https://m.lianjia.com/chuzu/bj/zufang/BJ2163171108206428160.html | 56 | 10500 | 元/月 | 远洋新干线 | 整租 |
4 | 5c712721397be4c52519fc09 | 1 | 1 | 阜成门 | 北京 | 西城 | 886 | 东 | 1 | 近地铁 集中供暖 随时看房 | 南露园 1室1厅 5600元 | 39.93066 | 1室1厅1卫 | 116.3485 | https://m.lianjia.com/chuzu/bj/zufang/BJ2173622775712063488.html | 43 | 5600 | 元/月 | 南露园 | 整租 |
5 | 5c7123bd397be4c52519f7af | 1 | 2 | 和平里 | 北京 | 朝阳 | 779 | 东 南 | 1 | 近地铁 集中供暖 | 和平里东街15号院 2室1厅 6300元 | 39.95708 | 2室1厅1卫 | 116.4314 | https://m.lianjia.com/chuzu/bj/zufang/BJ2158698783390056448.html | 56 | 6300 | 元/月 | 和平里东街15号院 | 整租 |
6 | 5c72ae43397be4c5251e2d7e | 1 | 2 | 奥林匹克公园 | 北京 | 朝阳 | 1139 | 南 北 | 2 | 精装 随时看房 | 整租 · 澳林春天四期 南北通透精装两居室 距奥森一路之隔 | 40.01826 | 2室2厅1卫 | 116.3807 | https://m.lianjia.com/chuzu/bj/zufang/BJ2158677644206948352.html | 111 | 12000 | 元/月 | 澳林春天四期 | 整租 |
#修改编号
data$X_id<-c(1:12000)
#修改数据类型
data$rent_area<-as.numeric(data$rent_area)
data$distance<-as.numeric(data$distance)
data$rent_price_listing<-as.numeric(data$rent_price_listing)
Warning message in eval(expr, envir, enclos):
"强制改变过程中产生了NA"
Warning message in eval(expr, envir, enclos):
"强制改变过程中产生了NA"
head(data)
X_id | bathroom_num | bedroom_num | bizcircle_name | city | dist | distance | frame_orientation | hall_num | house_tag | house_title | latitude | layout | longitude | m_url | rent_area | rent_price_listing | rent_price_unit | resblock_name | type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <chr> | <chr> | <chr> | <dbl> | <chr> | <int> | <chr> | <chr> | <dbl> | <chr> | <dbl> | <chr> | <dbl> | <dbl> | <chr> | <chr> | <chr> | |
1 | 1 | 2 | 3 | 上地 | 北京 | 海淀 | NA | 南 北 | 2 | 精装 集中供暖 双卫生间 | 整租 · 上地西里二层三居 自住出租 随时入住采光好 无遮挡 | 40.03900 | 3室2厅2卫 | 116.3178 | https://m.lianjia.com/chuzu/bj/zufang/BJ2135934725586690048.html | 137 | 15000 | 元/月 | 上地西里 | 整租 |
2 | 2 | 1 | 2 | 北大地 | 北京 | 丰台 | NA | 南 北 | 1 | 集中供暖 | 整租 · 丰台北大地电报局街家具家电齐全南北向两居 | 39.85666 | 2室1厅1卫 | 116.2923 | https://m.lianjia.com/chuzu/bj/zufang/BJ2101229402263126016.html | 57 | 4500 | 元/月 | 电报局街 | 整租 |
3 | 3 | 1 | 1 | 燕莎 | 北京 | 朝阳 | 788 | 北 | 1 | 近地铁 精装 集中供暖 | 整租 · 远洋新干线 1室1厅 10500元 | 39.96323 | 1室1厅1卫 | 116.4661 | https://m.lianjia.com/chuzu/bj/zufang/BJ2163171108206428160.html | 56 | 10500 | 元/月 | 远洋新干线 | 整租 |
4 | 4 | 1 | 1 | 阜成门 | 北京 | 西城 | 886 | 东 | 1 | 近地铁 集中供暖 随时看房 | 南露园 1室1厅 5600元 | 39.93066 | 1室1厅1卫 | 116.3485 | https://m.lianjia.com/chuzu/bj/zufang/BJ2173622775712063488.html | 43 | 5600 | 元/月 | 南露园 | 整租 |
5 | 5 | 1 | 2 | 和平里 | 北京 | 朝阳 | 779 | 东 南 | 1 | 近地铁 集中供暖 | 和平里东街15号院 2室1厅 6300元 | 39.95708 | 2室1厅1卫 | 116.4314 | https://m.lianjia.com/chuzu/bj/zufang/BJ2158698783390056448.html | 56 | 6300 | 元/月 | 和平里东街15号院 | 整租 |
6 | 6 | 1 | 2 | 奥林匹克公园 | 北京 | 朝阳 | 1139 | 南 北 | 2 | 精装 随时看房 | 整租 · 澳林春天四期 南北通透精装两居室 距奥森一路之隔 | 40.01826 | 2室2厅1卫 | 116.3807 | https://m.lianjia.com/chuzu/bj/zufang/BJ2158677644206948352.html | 111 | 12000 | 元/月 | 澳林春天四期 | 整租 |
## 可视化查看数据是否有缺失值
library(VIM)
aggr(data)
可知与地铁站距离distance缺失值较多,主要由于部分地区没有相邻地铁站,故缺失,可标注为无地铁。
同时经纬度有少量的缺失,占比极小,对分析结果基本无影响,可利用统计方法进行填补。填补经纬度,用数据前后的数据填补
其余缺失值均采用均值填充。
colnames(data)
- 'X_id'
- 'bathroom_num'
- 'bedroom_num'
- 'bizcircle_name'
- 'city'
- 'dist'
- 'distance'
- 'frame_orientation'
- 'hall_num'
- 'house_tag'
- 'house_title'
- 'latitude'
- 'layout'
- 'longitude'
- 'm_url'
- 'rent_area'
- 'rent_price_listing'
- 'rent_price_unit'
- 'resblock_name'
- 'type'
#填补地铁距离
data$distance[is.na(data$distance)] <-c(10000)
#填补经纬度,用数据前后的数据填补
library(zoo)
data$latitude <- na.locf(data$latitude)
data$longitude <- na.locf(data$longitude)
data$rent_area[is.na(data$rent_area)] <- mean(data$rent_area,na.rm = TRUE)
data$rent_price_listing[is.na(data$rent_price_listing)]<- mean(data$rent_price_listing,na.rm = TRUE)
## 可视化查看数据是否有缺失值
library(VIM)
aggr(data)
此时可知,数据填补完成,数据完整,可进一步描述分析
二、描述性统计
#查看城市数量
table(data$city)
北京 广州 上海 深圳
3000 3000 3000 3000
#区级分析
table(data$dist)
白云 宝安区 宝山 昌平 朝阳 崇明 从化
681 588 167 171 1049 1 21
大鹏新区 大兴 东城 番禺 房山 丰台 奉贤
2 221 64 555 111 319 57
福田区 光明区 海淀 海珠 虹口 黄浦 嘉定
491 69 330 279 78 111 189
金山 静安 荔湾 龙岗区 龙华区 罗湖区 门头沟
4 91 221 596 373 238 91
闵行 南沙 南山区 坪山区 浦东 普陀 青浦
287 52 608 9 794 192 173
石景山 顺义 松江 天河 通州 西城 徐汇
61 107 263 556 219 201 215
盐田区 杨浦 亦庄开发区 越秀 增城 闸北 长宁
26 108 56 266 369 90 180
2.1 区级租金箱线图
#区级箱线图
library(ggthemes)
g <- ggplot(data, aes(dist, rent_price_listing))
g + geom_boxplot(aes(fill=factor(dist))) +
theme(axis.text.x = element_text(angle=65, vjust=0.6)) +
labs(title="Box plot",
subtitle="City rent_price_listing",
caption="Source: mpg",
x="Class of Vehicle",
y="City Mileage")
Warning message:
"package 'ggthemes' was built under R version 4.0.4"
PS:可以用各区的平均值来做聚类分析,区分高低租金的行政区
#租房类型分布
table(data$type)
合租 整租
414 11586
2.2 租金分布情况
#所有租金分布
hist(data$rent_price_listing, prob = TRUE, col = "red",main="Normal Distribution")
#简单对数据集进行拆分
bjhouse<-data[which(data$city=='北京'),]
shhouse<-data[which(data$city=='上海'),]
szhouse<-data[which(data$city=='深圳'),]
gzhouse<-data[which(data$city=='广州'),]
#北京租金分布
hist(bjhouse$rent_price_listing, prob = TRUE, col = "red",main="Normal Distribution")
#深圳租金分布
hist(szhouse$rent_price_listing, prob = TRUE, col = "red",main="Normal Distribution")
2.3 北京各行政区租金分布
library(reshape2)
library(ggplot2)
library(ggridges)
library(RColorBrewer)
colormap <- colorRampPalette(rev(brewer.pal(11,'Spectral')))(32)
dt<-bjhouse[,c(6,17)]
colnames(dt)<-c("主题","风险")
splitdata<-split(dt,dt$主题)
xmax<-max(dt$`风险`)*1.1
xmin<-min(dt$`风险`)*1.1
N<-length(splitdata)
labels_y<-names(splitdata)
mydata<-data.frame(x=numeric(),y=numeric(),variable=numeric()) #?????յ?Data.Frame
for (i in 1:N){
tempy<-density(splitdata[[i]][2]$`风险`,bw = 3.37,from=xmin, to=xmax)
newdata<-data.frame(x=tempy$x,y=tempy$y)
newdata$variable<-i
mydata<-rbind(mydata,newdata)
}
Step<-max(mydata$y)*0.6
mydata$offest<--as.numeric(mydata$variable)*Step
mydata$V1_density_offest<-mydata$y+mydata$offest
p<-ggplot()
for (i in 1:N){
p<-p+ geom_linerange(data=mydata[mydata$variable==i,],aes(x=x,ymin=offest,ymax=V1_density_offest,group=variable,color=y),size =1, alpha =1) +
geom_line(data=mydata[mydata$variable==i,],aes(x=x, y=V1_density_offest),color="black",size=0.5)
}
p+scale_color_gradientn(colours=colormap,name="Density")+
scale_y_continuous(breaks=seq(-Step,-Step*N,-Step),labels=labels_y)+
xlab("租金")+
ylab("行政区")+
theme_classic()+
theme(
panel.background=element_rect(fill="white",colour=NA),
panel.grid.major.x = element_line(colour = "grey80",size=.25),
panel.grid.major.y = element_line(colour = "grey60",size=.25),
axis.line = element_blank(),
text=element_text(size=15,colour = "black"),
plot.title=element_text(size=15,hjust=.3),
legend.position="right"
)
2.4 各城市租金分布对比图
data$rent_price_listing<-as.numeric(data$rent_price_listing)
#不同城市租金分布之间对比
library(beanplot)
par(mai=c(0.5,0.5,0.25,1.2))
beanplot(rent_price_listing~city, data,col = list("#FF6B5E", "#00C3C2"),
side = "both",xlab ="city",ylab ="value")
log="y" selected
2.5 北京各行政区租金分布之间对比(豆荚图)
#北京租金分布之间对比
library(beanplot)
par(mai=c(0.5,0.5,0.25,1.2))
beanplot(rent_price_listing~dist, bjhouse,col = list("red", "#00C3C2"),
side = "both",xlab ="city",ylab ="value")
log="y" selected
2.6 整租房屋中,不同卧室数量租金分布情况对比
zzdata<-data[which(data$type=='整租'),]
#房型分布之间对比
library(beanplot)
par(mai=c(0.5,0.5,0.25,1.2))
beanplot(rent_price_listing~bedroom_num, zzdata,col = list("red", "#00C3C2"),
side = "both",xlab ="city",ylab ="value")
log="y" selected
2.7 不同城市各数据矩阵散点图
# 矩阵散点图
library(ggplot2)
library(GGally)
ggdata<-data[,c(2,3,7,16,17,5)]
ggscatmat(data =ggdata,columns = 1:5,color = "city",alpha = 0.8)+
theme_bw(base_family = "STKaiti",base_size = 10)+
theme(plot.title = element_text(hjust = 0.5))+
ggtitle("矩阵散点图")
三、数据探索
3.1面积和租金价格分布图
##面积和租金价格分布图
library(ggplot2)
library(RColorBrewer)
library(ggpubr)
ggscatterhist(
zzdata, x ='rent_area', y = 'rent_price_listing', shape=21,fill="#00AFBB",color = "black",size = 3, alpha = 1,
#palette = c("#00AFBB", "#E7B800", "#FC4E07"),
margin.params = list( fill="#00AFBB",color = "black", size = 0.2,alpha=1),
margin.plot = "histogram",
legend = c(0.8,0.8),
ggtheme = theme_minimal())
可发现,房屋面积与房租之间存在一定线性关系
3.2 地铁距离和租金价格分布图
##地铁价格和租金价格分布图
bj<-bjhouse[which(bjhouse$distance!=10000),]
bj<-bj[which(bj$type=='整租'),]
library(ggplot2)
library(RColorBrewer)
library(ggpubr)
ggscatterhist(
bj, x ='distance', y = 'rent_price_listing', shape=21,fill="#00AFBB",color = "black",size = 3, alpha = 1,
#palette = c("#00AFBB", "#E7B800", "#FC4E07"),
margin.params = list( fill="#00AFBB",color = "black", size = 0.2,alpha=1),
margin.plot = "histogram",
legend = c(0.8,0.8),
ggtheme = theme_minimal())
g <- ggplot(bj, aes(distance, rent_price_listing)) +
geom_count() +
geom_smooth(method="lm", se=F,color='red')
ggMarginal(g, type = "histogram", fill="blue")
ggMarginal(g, type = "boxplot", fill="transparent")
ggMarginal(g, type = "density", fill="transparent")
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
可发现有一定的线性关系,且离地铁越远,房租相应下降,但由于样本中,要么无地铁信息,要么都是附近有地铁的楼盘,而一定距离范围内,距离影响并不显著,故线性相关系数较低,若能获得缺失地铁信息的楼盘与地铁站的距离,结果应当会有更大发现。
3.3 经纬度信息挖掘
bjzz<-bjhouse[which(bjhouse$type=='整租'),]
library(dplyr)
bjzz<-arrange(bjzz,desc(bjzz$rent_price_listing))
#剔除一个极端大值
bjzz<-bjzz[-1,]
head(bjzz)
X_id | bathroom_num | bedroom_num | bizcircle_name | city | dist | distance | frame_orientation | hall_num | house_tag | house_title | latitude | layout | longitude | m_url | rent_area | rent_price_listing | rent_price_unit | resblock_name | type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <chr> | <chr> | <chr> | <dbl> | <chr> | <int> | <chr> | <chr> | <dbl> | <chr> | <dbl> | <chr> | <dbl> | <dbl> | <chr> | <chr> | <chr> | |
2 | 2021 | 2 | 4 | CBD | 北京 | 朝阳 | 372 | 南 | 1 | 近地铁 集中供暖 随时看房 | 阳光100 4室1厅 99450元 | 39.91839 | 4室1厅2卫 | 116.4815 | https://m.lianjia.com/chuzu/bj/zufang/BJ2169359626858921984.html | 243 | 99450 | 元/月 | 阳光100 | 整租 |
3 | 580 | 2 | 4 | 方庄 | 北京 | 朝阳 | 21 | 南 北 | 2 | 近地铁 双卫生间 随时看房 | 整租 · 时代芳群一层复式,临街带花园。 跃层 | 39.87101 | 4室2厅2卫 | 116.4300 | https://m.lianjia.com/chuzu/bj/zufang/BJ2045376803442532352.html | 261 | 95000 | 元/月 | 时代芳群 | 整租 |
4 | 1986 | 6 | 6 | 中央别墅区 | 北京 | 朝阳 | 10000 | 东 南 北 | 2 | 精装 | 整租 · 卓锦万代精装6居室,房子状况新,诚意出租 | 40.03153 | 6室2厅6卫 | 116.5389 | https://m.lianjia.com/chuzu/bj/zufang/BJ2024422078433992704.html | 312 | 90000 | 元/月 | 卓锦万代 | 整租 |
5 | 147 | 1 | 3 | 苏州桥 | 北京 | 海淀 | 553 | 南 北 | 1 | 近地铁 集中供暖 | 整租 · 海淀区可随时使用的中关村SOHO | 39.98945 | 4房间1卫 | 116.3167 | https://m.lianjia.com/chuzu/bj/zufang/BJ2059876706667200512.html | 223 | 82500 | 元/月 | 中关村SOHO | 整租 |
6 | 515 | 2 | 6 | 方庄 | 北京 | 朝阳 | 21 | 南 北 | 2 | 近地铁 双卫生间 | 整租 · 时代芳群 6室2厅 80000元 | 39.87101 | 6室2厅2卫 | 116.4300 | https://m.lianjia.com/chuzu/bj/zufang/BJ2095502709607104512.html | 328 | 80000 | 元/月 | 时代芳群 | 整租 |
7 | 431 | 3 | 3 | 建国门外 | 北京 | 朝阳 | 660 | 东 南 西 北 | 1 | 近地铁 精装 集中供暖 | 整租 · 嘉华世纪 南北通透两层复式带空中花园 精装修 | 39.91155 | 3室1厅3卫 | 116.4470 | https://m.lianjia.com/chuzu/bj/zufang/BJ1967782834081112064.html | 214 | 79000 | 元/月 | 嘉华世纪公寓 | 整租 |
#上海可视化
ggplot(shhouse, aes(x = latitude, y = longitude, fill=rent_price_listing)) +
geom_point(shape=21,size=4,colour="black",alpha=0.95) +
scale_fill_distiller(palette="RdYlBu")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",hjust=.5,color="black"),
legend.background = element_blank(),
legend.position=c(0.85,0.2)
)
summary(bjzz$rent_price_listing)
Min. 1st Qu. Median Mean 3rd Qu. Max.
900 4800 6500 8948 9500 99450
# 给用户打上类型标签
bjzz$pricetype<- "4800元以下"
bjzz[bjzz$rent_price_listing>=4800 & bjzz$rent_price_listing<6500,'pricetype'] <- "4800-6500元"
bjzz[bjzz$rent_price_listing>=6500 & bjzz$rent_price_listing<9500 ,'pricetype'] <- "6500-9500元"
bjzz[bjzz$rent_price_listing>=9500 & bjzz$rent_price_listing<=99450,'pricetype'] <- "大于9500元"
head(bjzz)
X_id | bathroom_num | bedroom_num | bizcircle_name | city | dist | distance | frame_orientation | hall_num | house_tag | ... | latitude | layout | longitude | m_url | rent_area | rent_price_listing | rent_price_unit | resblock_name | type | pricetype | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <chr> | <chr> | <chr> | <dbl> | <chr> | <int> | <chr> | ... | <dbl> | <chr> | <dbl> | <chr> | <dbl> | <dbl> | <chr> | <chr> | <chr> | <chr> | |
2 | 2021 | 2 | 4 | CBD | 北京 | 朝阳 | 372 | 南 | 1 | 近地铁 集中供暖 随时看房 | ... | 39.91839 | 4室1厅2卫 | 116.4815 | https://m.lianjia.com/chuzu/bj/zufang/BJ2169359626858921984.html | 243 | 99450 | 元/月 | 阳光100 | 整租 | 大于9500元 |
3 | 580 | 2 | 4 | 方庄 | 北京 | 朝阳 | 21 | 南 北 | 2 | 近地铁 双卫生间 随时看房 | ... | 39.87101 | 4室2厅2卫 | 116.4300 | https://m.lianjia.com/chuzu/bj/zufang/BJ2045376803442532352.html | 261 | 95000 | 元/月 | 时代芳群 | 整租 | 大于9500元 |
4 | 1986 | 6 | 6 | 中央别墅区 | 北京 | 朝阳 | 10000 | 东 南 北 | 2 | 精装 | ... | 40.03153 | 6室2厅6卫 | 116.5389 | https://m.lianjia.com/chuzu/bj/zufang/BJ2024422078433992704.html | 312 | 90000 | 元/月 | 卓锦万代 | 整租 | 大于9500元 |
5 | 147 | 1 | 3 | 苏州桥 | 北京 | 海淀 | 553 | 南 北 | 1 | 近地铁 集中供暖 | ... | 39.98945 | 4房间1卫 | 116.3167 | https://m.lianjia.com/chuzu/bj/zufang/BJ2059876706667200512.html | 223 | 82500 | 元/月 | 中关村SOHO | 整租 | 大于9500元 |
6 | 515 | 2 | 6 | 方庄 | 北京 | 朝阳 | 21 | 南 北 | 2 | 近地铁 双卫生间 | ... | 39.87101 | 6室2厅2卫 | 116.4300 | https://m.lianjia.com/chuzu/bj/zufang/BJ2095502709607104512.html | 328 | 80000 | 元/月 | 时代芳群 | 整租 | 大于9500元 |
7 | 431 | 3 | 3 | 建国门外 | 北京 | 朝阳 | 660 | 东 南 西 北 | 1 | 近地铁 精装 集中供暖 | ... | 39.91155 | 3室1厅3卫 | 116.4470 | https://m.lianjia.com/chuzu/bj/zufang/BJ1967782834081112064.html | 214 | 79000 | 元/月 | 嘉华世纪公寓 | 整租 | 大于9500元 |
#北京房源分布图
library(ggplot2)
library(RColorBrewer)
library(ggpubr)
ggscatterhist(
bjzz, x ='latitude', y = 'longitude', #iris
shape=21,color ="black",fill= "pricetype", size =4, alpha = 0.8,
palette = c("#00AFBB", "#E7B800", "#FC4E07","pink"),
margin.plot = "density",
margin.params = list(fill = "pricetype", color = "black", size = 0.2),
legend = c(0.9,0.15),
ggtheme = theme_minimal())
由图可知,高租金房源多集中在中心位置,因为地段繁华,寸土寸金,且写字楼林立,供不应求,故租金高昂,符合常理,而外围分布散乱,离市中心较远,交通不变,故符合实情。
#北京房源分布图
library(ggplot2)
library(RColorBrewer)
library(ggpubr)
ggscatterhist(
bjzz, x ='latitude', y = 'longitude', shape=21,fill="#00AFBB",color = "black",size = 3, alpha = 1,
#palette = c("#00AFBB", "#E7B800", "#FC4E07"),
margin.params = list( fill="#00AFBB",color = "black", size = 0.2,alpha=1),
margin.plot = "histogram",
legend = c(0.8,0.8),
ggtheme = theme_minimal())
由经纬度信息,还原房源位置分布情况,由于正中心属于故宫天安门等区域,不存在在租房源,故除中心外,是向外扩散趋势,符合常理。可考虑结合颜色信息,对租金大小进行可视化。
# 给用户打上类型标签
shhouse$pricetype<- "4800元以下"
shhouse[shhouse$rent_price_listing>=4800 & shhouse$rent_price_listing<6500,'pricetype'] <- "4800-6500元"
shhouse[shhouse$rent_price_listing>=6500 & shhouse$rent_price_listing<9500 ,'pricetype'] <- "6500-9500元"
shhouse[shhouse$rent_price_listing>=9500 & shhouse$rent_price_listing<=99450,'pricetype'] <- "大于9500元"
head(shhouse)
##上海分布图
library(ggplot2)
library(RColorBrewer)
library(ggpubr)
ggscatterhist(
shhouse, x ='latitude', y = 'longitude', #iris
shape=21,color ="black",fill= "pricetype", size =4, alpha = 0.8,
palette = c("#00AFBB", "#E7B800", "#FC4E07","pink"),
margin.plot = "density",
margin.params = list(fill = "pricetype", color = "black", size = 0.2),
legend = c(0.9,0.15),
ggtheme = theme_minimal())
同理
同时也可结合GeoQ地图可视化平台,简单快捷地进行可视化。
或者
可结合道路分布,沿海情况等信息进行分析。
也可尝试结合R shiny包应用,建立交互地图可视化工具。可参考另一篇文章《2017年国赛拍照赚钱问题地图可视化APP(shiny)》
《2017年国赛拍照赚钱问题地图可视化APP(shiny)》
也可尝试使用机器学习算法建立租金预测模型,参考文章:《利用机器学习方法对猪肉价格预测》
《利用机器学习方法对猪肉价格预测》