R中多个变量的线图 [英] Line plot of multiple variables in R
本文介绍了R中多个变量的线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
xyz
0 2.2 4.5
5 3.8 6.8
10 4.6 9.3
15 7.6 10.5
如何绘制xy散点图在R中绘制如excel(显示如下)?
解决方案
至少有四种方法可以做到这一点:
)在这里使用一个水平或宽的data.frame叫做df
$ b
df < - 数据(x = c(0,5,10,15),y = c(2.2,3.8,4.6,7.6),z = c(4.5,6.8,9.3,10.5))
ggplot(df, aes(x))+
geom_line(aes(y = y,color =y))+
geom_line(aes(y = z,color =z))
<2>使用格子
require(lattice)
xyplot(x〜y + z,data = df,type = c('l','l'),col = c(blue,red),auto。 key = T)
3)将您的原始df转换为longdata.frame。这就是你如何使用 ggplot2
require(reshape)
require(ggplot2)
mdf < - melt(df,id =x)#转换为长格式
ggplot(mdf ,aes(x = x,y = value,color = variable))+
geom_line()+
theme_bw()
查看全文