Plots with a common x axis

2019-07-07 02:41发布

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

I tried:

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?

标签: r ggplot2
1条回答
The star\"
2楼-- · 2019-07-07 03:34
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") 
查看更多
登录 后发表回答