2014-02-28 88 views
1

所以我的题为Site.377在x轴我想这是在X柱,然后将其它4列都有权Results1Results2的时间的大的数据集的线图,和Results3。我想把它们全部放在同一个图表上,以比较Results1到3随着时间的推移如何相互比较。绘制与R中的多个列

我目前所做的是:

library(ggplot2) 
p <- ggplot(Site.377, aes(x=X, y = Results1) #This was just an attempt to get one of them to post 
p + geom_line() 

当我会做到这一点,得到的情节也只是都smushed一起堆放在一旁的数值。好像一列数字重叠。

任何帮助将不胜感激。

X Results1 Results2 
1  0  .23 
2 .83  0 
3 .56  .62 
4  0  .11 
+1

你能张贴dput的'输出(头提供数据的样本(网站后.377))'。 '绘制reshape2 :: melt'并将'colour'添加到'aes'可能是您想要做的类似于http://stackoverflow.com/questions/21616688/ggplot-not-adding-legend-what-am- i-missing-very-to-r/21616934#21616934 –

+0

该集合中的数据量太大而无法在dput(head(Site.377))中发布结果。我刚刚尝试过:ggplot(Site.377,aes(x = X,y = Results1))+ geom_line(color =“black”) 并且具有相同的结果。我可能误解了你所说的话。 – user3363054

+0

你能提供数据的前几列吗?像'dput(head(Site.377 [1:10]))''。或者创建具有相同特征并产生相同问题的数据。我猜这样的东西会工作'dfm < - melt(Site.377,id.vars =“X”); ggplot(dfm,aes(x = X,y = value,color = variable))+ geom_line()' –

回答

4

你不想你可以通过子集化Site.377你融化之前离开任何列。或子集基于variable你融化它

幸运的猜测在评论:)

library(ggplot2) 
library(reshape2) 


dfm <- melt(Site.377, id.vars = "X") 

p <- ggplot(dfm, aes(x = X, y = value, colour = variable)) 
p + geom_line() 

enter image description here