再一次遇到了一个复杂的ggplot。我想要使用facet网格在一个小区内绘制不同的小区类型。facet_grid中的不同Plottypes
我希望我可以使用下面的例子清楚表达我的观点: 我想生成一个类似于第一张图的图,但上面的图应该看起来像第二张图。 我已经找到了使用子集函数的技巧,但我不能将垂直线添加到只有一个绘图,更不用说两个或三个(或指定颜色)。
CODE:
a <- rnorm(100)
b <- rnorm(100,8,1)
c <- rep(c(0,1),50)
dfr <- data.frame(a=a,b=b,c=c,d=seq(1:100))
dfr_melt <- melt(dfr,id.vars="d")
#I want only two grids, not three
ggplot(dfr_melt,aes(x=d,y=value)) + facet_grid(variable~.,scales="free")+
geom_line(subset=.(variable=="a")) + geom_line(subset=.(variable=="b"))
#Upper plot should look like this
ggplot(dfr,aes(x=d,y=a)) + geom_line() + geom_line(aes(y=c,color="c"))+
geom_hline(aes(yintercept=1),linetype="dashed")+
geom_hline(aes(yintercept=-2),linetype="dashed")
btw:谁能告诉我为什么我的问候总是被省略。它看起来像我是一个不友好的人,我不是! – rainer
不鼓励添加问候语:http://meta.stackexchange.com/q/2950/161858 – Andrie
请在您的代码中添加一些空格,以便阅读起来更加轻松。 “<-'和','周围缺少空格会让我的眼睛受伤。 – Andrie