R 如何在一个图形上绘制三个矢量/折线图?

R 如何在一个图形上绘制三个矢量/折线图?,r,R,如何在R中用三条线绘制一个折线图 min我们可以在cbind之后使用matplot对向量进行排序s来创建矩阵 matplot(cbind(min, max, d), type='l') 要更改“x轴”标签,我们可以使用xaxt=n绘图,并使用axis matplot(cbind(min, max, d), type='l', xaxt='n', col=2:4) axis(1, at=1:4, labels=letters[1:4]) legend('topright', legend=c('

如何在R中用三条线绘制一个折线图


min我们可以在
cbind
之后使用
matplot
向量进行排序
s来创建
矩阵

matplot(cbind(min, max, d), type='l')
要更改“x轴”标签,我们可以使用
xaxt=n
绘图,并使用
axis

matplot(cbind(min, max, d), type='l', xaxt='n', col=2:4)
axis(1, at=1:4, labels=letters[1:4])
legend('topright', legend=c('min', 'max', 'd'), col=2:4, pch=1)

完成@akrun非常好答案的另一个解决方案,基于:

require(ggplot2)
要求(2)
需要(directlabels)

是否可以在x轴上添加标签,如“a”、“b”、“c”、“d”?@zone1您的示例是数字数据。所以,我不知道你想去哪里label@zone1也许
matplot(cbind(min,max,d),type='l',xaxt='n');轴(1,at=1:4,标签=字母[1:4])
了解directlabels很好
matplot(cbind(min, max, d), type='l', xaxt='n', col=2:4)
axis(1, at=1:4, labels=letters[1:4])
legend('topright', legend=c('min', 'max', 'd'), col=2:4, pch=1)
require(ggplot2)
require(reshape2)
require(directlabels)

min <- c( 1, 1, 4, 5)
max <- c( 8, 9, 8, 10)
d   <- c(-2, 3, 4, 3)

df <- data.frame(min=min, max=max, d=d, x=1:4)
df.m <- melt(df,id.vars="x")

p <- ggplot(df.m, aes(x=x, y=value, color=variable)) + geom_line()

direct.label(p)