R语言 : 读取csv 文件, 画基金净值线

数据文件 66001.txt 内容格式:

date1,jz0,jz1,jz2,jz3,jz4,jz5

2017-09-01,1.0202,1.6531,2.4647,1.1081,NA,2.9068
2017-09-04,1.0134,1.6621,2.4576,1.1083,NA,2.8983
2017-09-05,1.0168,1.6637,2.4616,1.1085,NA,2.9010

 ... ...

xts 是基于 zoo 的时间序列

xts_funds.R 代码:

library(zoo)
setwd("D:/test")
data <- read.csv("66001.txt", header=TRUE, sep=",")
class(data)
head(data)
dates <- as.Date(data$date1, "%Y-%m-%d")
attach(data)
plot(dates,jz0, type="l", lwd=1, main="基金净值图", xlab="日期",ylab="净值",ylim=c(0.5,4.0));
lines(dates,jz1, type="l", lwd=1, col="blue")
lines(dates,jz2, type="l", lwd=1, col="green")
lines(dates,jz3, type="l", lwd=1, col="yellow")
lines(dates,jz4, type="l", lwd=1, col="red")
lines(dates,jz5, type="l", lwd=1, col="purple")
grid()
detach(data)
jjdm <- c("660010","660011","660012","660013","660014","660015")
color <- c("black","blue","green","yellow","red","purple")
legend("topleft", jjdm, pch=c(0,0,0,0,0,0), col=color, cex=0.6); # 图例

参考书: [ R in Action 第2版 ] 第3章 图形初阶 : 3.5 图形的组合

xts_fund6.R 代码:

library(xts)
setwd("D:/test")
data <- read.csv("66001.txt", header=TRUE, sep=",")
class(data)
dates <- as.Date(data$date1, "%Y-%m-%d")
attach(data)
opar <- par(no.readonly=TRUE)
par(mfrow= c(2,3), oma= c(0,0, 3,0)) # 2行3列
plot(dates, jz0, type="l", lwd=1,  main="660010", xlab="date", ylab="value", col="black")
text(x=200, y=200, labels="fund net value")
grid()
plot(dates, jz1, type="l", lwd=1,  main="660011", xlab="date", ylab="value", col="blue")
grid()
plot(dates, jz2, type="l", lwd=1,  main="660012", xlab="date", ylab="value", col="green")
grid()
plot(dates, jz3, type="l", lwd=1,  main="660013", xlab="date", ylab="value", col="yellow")
grid()
plot(dates, jz4, type="l", lwd=1,  main="660014", xlab="date", ylab="value", col="red")
grid()
plot(dates, jz5, type="l", lwd=1,  main="660015", xlab="date", ylab="value", col="purple")
grid()
mtext("6个基金净值图", side=3, line=0, outer=T) # 总的标题
par(opar)
detach(data)



  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值