我有一个由8826个对象和4个变量组成的组合数据集。我的列名是tVec、yVec、tVec、yVec。
我需要将x轴上的2个yVec绘制为带有图例的单个tVec。我尝试了下面的方法,但只绘制了一个图。
plotnew <- ggplot(data=combined, aes(x=tVec, y= yVec, colour='variable')) + geom_line()
Plot如下所示:
关于这个的任何线索。我已经厌倦了很多例子。只是做得不对。
谢谢。
发布于 2017-07-20 15:58:08
您需要格式化您的输入data.frame:
combined = data.frame(tVec=1:100,yVec=rnorm(100),tVec=101:200,yVec=rnorm(100))
df = rbind(data.frame(x=combined$tVec,y=combined$yVec,label="first"),
data.frame(x=combined$tVec.1,y=combined$yVec.1,label="second"))
library(ggplot2)
plotnew <- ggplot(data=df, aes(x, y, colour=label))+
geom_line()
或
df = rbind(data.frame(x=combined$tVec,y=combined$yVec,label="first"),
data.frame(x=combined$tVec,y=combined$yVec.1,label="second"))
library(ggplot2)
plotnew <- ggplot(data=df, aes(x, y, colour=label))+
geom_line()
希望对您有所帮助
https://stackoverflow.com/questions/45219099
复制相似问题