具有公共x轴的图 [英] Plots with a common x axis

查看:70
本文介绍了具有公共x轴的图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个data.frame df,其列为TV1V2V3V4 我想制作一个包含两个以T为共同x轴的图的ggplot 第一个情节包含V1 第二个图包含V2V3V4

I have a data.frame df with columns T ,V1,V2,V3,V4 I would like to make a ggplot containing two plots with T as the common the x axis The first plot contains V1 The second plot contains V2,V3,V4

我尝试过:

m1 <- melt(df, id = "T") 

chart1<-qplot(T, value, data = m1, geom = "line", group = variable) +
stat_smooth() +
facet_grid(variable ~ ., scale = "free_y") 

但这给了我四个共同的情节,而我只想两个. 有办法吗?

But this gives me four common plots whereas I just want two. Is there a way to do this?

推荐答案

library(ggplot2)
library("reshape")

df <- data.frame(T,V1,V2,V3,V4)
m1 <- melt(df, id = "T") 

m1$sepfac <- (m1$variable=="V1")

chart1<-qplot(T, value, data = m1, geom = "line", group = variable) +
stat_smooth() +
facet_grid(sepfac~., scale = "free_y") 

这篇关于具有公共x轴的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆