楼主: 耕耘使者
13895 31

[问答] 怎样生成这样的时间序列图? [推广有奖]

贵宾

已卖:5006份资源

学术权威

39%

还不是VIP/贵宾

-

威望
4
论坛币
1811021 个
通用积分
171.7911
学术水平
109 点
热心指数
173 点
信用等级
87 点
经验
93428 点
帖子
4549
精华
0
在线时间
2848 小时
注册时间
2006-4-6
最后登录
2025-7-12

楼主
耕耘使者 发表于 2012-3-14 10:46:45 |AI写论文
500论坛币
我有数据,见附件:
x1.zip (459 Bytes) 本附件包括:
  • x1.csv

想用R生成下面这样的时间序列图(不是一个图一个图单作,而是像下图一样包含在一张图中!):
ChinaIncome_001_big.png
请问该如何做?

最佳答案

kk22boy 查看完整内容

rm(list=ls()) par(mfrow=c(3,2),mar=c(0,4,0,2), oma = c(3, 0, 2, 0)) data=read.csv("x1.csv",header=T) attach(data) plot(year,y1,xaxt="n", xlab = "", type = "l") plot(year,y2,xaxt="n", xlab = "", type = "l") plot(year,y3,xaxt="n", xlab = "", type = "l") plot(year,y4,xaxt="n", xlab = "", type = "l") plot(year,y5, xlab = "", type = "l") plot(year,y7, xlab = "", type = "l") 另外距离近一 ...
关键词:时间序列 张图中 如何

沙发
kk22boy 发表于 2012-3-14 10:46:46
耕耘使者 发表于 2012-3-14 19:54
太好了,但能否让y1等离纵轴近一些?或者让他们大一些?
因为看不清楚是哪个模型的了
rm(list=ls())
par(mfrow=c(3,2),mar=c(0,4,0,2), oma = c(3, 0, 2, 0))
data=read.csv("x1.csv",header=T)
attach(data)
plot(year,y1,xaxt="n", xlab = "", type = "l")
plot(year,y2,xaxt="n", xlab = "", type = "l")
plot(year,y3,xaxt="n", xlab = "", type = "l")
plot(year,y4,xaxt="n", xlab = "", type = "l")
plot(year,y5, xlab = "", type = "l")
plot(year,y7, xlab = "", type = "l")

Rplot.jpeg
另外距离近一点的话还是问版主吧,呵呵
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
epoh + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

如果该贴对您有些许帮助,希望你能回复一下或者评一下热心指数!谢谢!

藤椅
universe110 发表于 2012-3-14 11:07:33
看不大清楚图的坐标值。给你个参考,可以对应着y1~y7做你想要的图。
我习惯读txt格式数据,所以把csv转化成txt.
R code:
da=read.table("x1.txt",header=T)
plot(da$year,da$y1,type="l",ylab="agriculture",xlab="time")

已有 1 人评分学术水平 热心指数 收起 理由
耕耘使者 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1   查看全部评分

板凳
耕耘使者 发表于 2012-3-14 11:19:54
universe110 发表于 2012-3-14 11:07
看不大清楚图的坐标值。给你个参考,可以对应着y1~y7做你想要的图。
我习惯读txt格式数据,所以把csv转化成 ...
不是这样的,是如附图那样,同时做所有的变量图,最后显示在一张图上

报纸
qoiqpwqr 发表于 2012-3-14 11:28:43
x1 <- rnorm(30)
x2 <- rnorm(30)
x3 <- rnorm(30)
x4 <- rnorm(30)
x5 <- rnorm(30)

x <- cbind(c(1,2,3), c(4,5,6))
layout(x, c(1,1), c(3,2,3))
layout.show(5)

par(mar=c(0,5,5,2), oma = c(0, 0, 3, 0))
plot(x1, xaxt = "n", xlab = "", type = "l")
par(mar=c(0,5,0,2))
plot(x2, xaxt = "n", xlab = "", type = "l")
par(mar=c(5,5,0,2))
plot(x3, xlab = "Time", type = "l")
par(mar=c(0,5,5,2))
plot(x4, xaxt = "n", xlab = "", type = "l")
par(mar=c(0,5,0,2))
plot(x5, xlab = "Time", type = "l")
mtext("Time", side = 1, cex = 0.75, line = 3)
mtext("Big Title", outer = TRUE, cex = 1)
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
babymafia + 1 + 1 + 1 热心帮助其他会员
耕耘使者 + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

地板
耕耘使者 发表于 2012-3-14 11:41:50
qoiqpwqr 发表于 2012-3-14 11:28
x1
版主,我现在急着要用,一行一行学已经来不急了,你能否按附件中的数据文件把代码写出来?是六个变量。
呵呵,我太笨了

7
qoiqpwqr 发表于 2012-3-14 11:49:37
dat <- read.csv("x1.csv", header = T, sep = ",")
attach(dat)
x <- cbind(c(1,2,3), c(4,5,6))
layout(x, c(1,1), c(4,3,4))

par(mar=c(0,5,4,2), oma = c(0, 0, 3, 0))
plot(year, y1, xaxt = "n", xlab = "", type = "l")
par(mar=c(0,5,0,2))
plot(year, y2, xaxt = "n", xlab = "", type = "l")
par(mar=c(5,5,0,2))
plot(year, y3, xlab = "Time", type = "l")
par(mar=c(0,5,4,2))
plot(year, y4, xaxt = "n", xlab = "", type = "l")
par(mar=c(0,5,0,2))
plot(year, y5, xaxt = "n", xlab = "", type = "l")
par(mar=c(5,5,0,2))
plot(year, y7, xlab = "Time", type = "l")
mtext("Big Title", outer = TRUE, cex = 1)
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
aspenroad + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

8
耕耘使者 发表于 2012-3-14 13:31:24
qoiqpwqr 发表于 2012-3-14 11:49
dat
直接运行的错误是:
> plot(year, y1, xaxt = "n", xlab = "", type = "l")
错误于as.POSIXlt.numeric(x) : 'origin' must be supplied
> par(mar=c(0,5,0,2))
> plot(year, y2, xaxt = "n", xlab = "", type = "l")
错误于as.POSIXlt.numeric(x) : 'origin' must be supplied
> par(mar=c(5,5,0,2))
> plot(year, y3, xlab = "Time", type = "l")
错误于as.POSIXlt.numeric(x) : 'origin' must be supplied
> par(mar=c(0,5,4,2))
> plot(year, y4, xaxt = "n", xlab = "", type = "l")
错误于as.POSIXlt.numeric(x) : 'origin' must be supplied
> par(mar=c(0,5,0,2))
> plot(year, y5, xaxt = "n", xlab = "", type = "l")
错误于as.POSIXlt.numeric(x) : 'origin' must be supplied
> par(mar=c(5,5,0,2))
> plot(year, y7, xlab = "Time", type = "l")
错误于as.POSIXlt.numeric(x) : 'origin' must be supplied
> mtext("Big Title", outer = TRUE, cex = 1)
错误于mtext("Big Title", outer = TRUE, cex = 1) : 还没有调用plot.new

9
耕耘使者 发表于 2012-3-14 13:32:51
修改程序:用dat$year代替了year,
新的提示是:
> par(mar=c(0,5,4,2), oma = c(0, 0, 3, 0))
> plot(dat$year, y1, xaxt = "n", xlab = "", type = "l")
错误于xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
> par(mar=c(0,5,0,2))
> plot(dat$year, y2, xaxt = "n", xlab = "", type = "l")
错误于xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
> par(mar=c(5,5,0,2))
> plot(dat$year, y3, xlab = "Time", type = "l")
错误于xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
> par(mar=c(0,5,4,2))
> plot(dat$year, y4, xaxt = "n", xlab = "", type = "l")
错误于xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
> par(mar=c(0,5,0,2))
> plot(dat$year, y5, xaxt = "n", xlab = "", type = "l")
错误于xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
> par(mar=c(5,5,0,2))
> plot(dat$year, y7, xlab = "Time", type = "l")
错误于xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
> mtext("Big Title", outer = TRUE, cex = 1)
错误于mtext("Big Title", outer = TRUE, cex = 1) : 还没有调用plot.new
>

10
耕耘使者 发表于 2012-3-14 13:33:12
麻烦版主了!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-4 01:11