与共同的X轴绘制(Plots with a common x axis)

2019-09-19 03:26发布

我有一个data.frame DF与列TV1V2V3V4我想使包含两个曲线具有ggplot T作为共同的x轴的第一曲线包含V1的第二曲线包含V2V3V4

我试过了:

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

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

但是,这给了我四种常见的情节,而我只是想要两个。 有没有办法做到这一点?

Answer 1:

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") 


文章来源: Plots with a common x axis
标签: r ggplot2