0

我正在使用 Zillow 租金数据来确定过去 10 年的最高租金涨幅。我有一个按邮政编码由原始数据制作的时间序列折线图(显示 6 个最高价格上涨的邮政编码),但我想显示百分比增长而不是原始增长。

到目前为止,这是我的代码:

home=read.csv("Zip_ZriPerSqft_AllHomes.csv")
head(home)
colnames = names(home)
namefilter=grepl("X", names(home))
colnames(namefilter)
names = !namefilter
colnames[names]
install.packages("reshape")
library("reshape")
dallas = melt(home, id.vars=colnames[names], value.name ="Month_Year")
install.packages("dplyr")
library("dplyr")
periodCutter=function(x,i) {

  strsplit(x,"\\.")[[1]][i]
}
dallas$variable=as.character(dallas$variable)
dallas$variable=gsub("X","",dallas$variable)
years=vapply(dallas$variable,periodCutter,i=1,character(1))
months=vapply(dallas$variable,periodCutter,i=2,character(1))
dallas$year = years
dallas$month = months
head(dallas)
unique(years)
unique(months)
dallas2 = dallas %>% group_by(RegionName, year) %>% summarize(price=mean(value))
install.packages("ggplot2")
library(ggplot2)
ggplot(data = dallas2, aes(x=year, y=price, group = RegionName , color = RegionName)) +geom_line()

install.packages("gghighlight")
library(gghighlight)
gghighlight_line(dallas2, aes(year,price,color = RegionName), predicate = max(price), max_highlight =6) +theme_minimal()
gghighlight_line(dallas2, aes(year,price,color = RegionName), predicate = max(price), max_highlight =6) +theme_minimal() + facet_wrap(~RegionName)

这是我的图表到目前为止的样子

4

0 回答 0