r - 计算R中租金价格的百分比增长?
问题描述
我正在使用 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)
解决方案
推荐阅读
- sql - 基于输入范围和现有数据检索多个变量的 SQL 查询
- html - 当我在悬停时制作边框时,另一个元素稍微移动了,如何让它保持在它们的位置?
- django - 如何在真实服务器中获取我的 Django 应用程序?
- android - 如何使用 google fit android sdk 从所有数据源读取数据?
- acumatica - 在列配置中为所有用户隐藏列
- cors - 如何在“access_control_allow_origin”中设置两个地址?
- c# - C# WPF)窗口中控件的宽度奇怪地缩小
- sql-server - 第一个事务完成后,第二个事务仍在等待
- javascript - 如何将 EOL 转义序列与特定文件相关联?
- mysql - 为什么 R 上传数据比 KNIME 或 Workbench 快得多?