计算以R为单位的租金上涨百分比?

计算以R为单位的租金上涨百分比?,r,ggplot2,time-series,price,zillow,R,Ggplot2,Time Series,Price,Zillow,我使用低租金数据来确定过去10年中最高的租金增长。我有一个时间序列线图,由邮政编码的原始数据组成(显示6个最高价格上涨的邮政编码),但我想显示相对于原始上涨的百分比上涨 以下是我目前的代码: home=read.csv("Zip_ZriPerSqft_AllHomes.csv") head(home) colnames = names(home) namefilter=grepl("X", names(home)) colnames(namefilter) names = !namefilter

我使用低租金数据来确定过去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)

看看
?lag
函数,它允许您创建一个新的滞后变量,您可以很容易地从中获得百分比增加。您需要在月与年之间增加百分比吗?在任何情况下,您可能希望将这些变量转换为日期(而不是字符串),以便能够使用时间序列操纵functions@Romain谢谢,试一试!我在看几年之间的百分比增长。