我正在策划r中的barplot.
我的数据:
,Up,Down
Floor-1,690,1511
Maxim,1354,2515
Hosiptal,1358,2649
Bank,459,589
Air-port,1359,2097
Bus-stand,1234,1928
Taxi-Stand,213,138
Railway-station,557,610
Run Code Online (Sandbox Code Playgroud)
脚本的条形图位于: 链接到图像
因为我没有足够的声誉; 我无法发布图片...... :)
我的脚本是:
d <- read.csv("file.csv")
barplot(t(as.matrix(d[, 2:3])),beside=TRUE,legend = c("Up","Down"), ylab = "Number of steps",
xlab = "Building", main = "Up and Down steps",names.arg= as.matrix(d$X) ,col=rainbow(2),type="h")
Run Code Online (Sandbox Code Playgroud)
在该图中,缺少x轴"公交车站"和"火车站"的标签.
如何标记丢失的标签?
我想使用R执行傅立叶变换到时间序列.我想:
这是数据的链接:数据 链接
这是我的初始代码.
dat <- read.csv("Baguio.csv",header=FALSE)
y <- dat$V1
ssp <-spectrum(y)
t <- 1:73
per <- 1/ssp$freq[ssp$spec==max(ssp$spec)]
reslm <- lm(y ~ sin(2*pi/per*t)+cos(2*pi/per*t))
rg <- diff(range(y))
#blue dashed line
plot(y~t,ylim=c(min(y)-0.1*rg,max(y)+0.1*rg))
lines(fitted(reslm)~t,col=4,lty=2)
#green line 2nd harmonics
reslm2 <- lm(y ~ sin(2*pi/per*t)+cos(2*pi/per*t)+sin(4*pi/per*t)+cos(4*pi/per*t))
lines(fitted(reslm2)~t,col=3)
Run Code Online (Sandbox Code Playgroud)
有没有办法简化这段代码?如果我必须达到18次谐波,则等式变得非常长.另外,我仍然不知道如何在这里添加谐波.
提前谢谢了,