2014-02-26 66 views
3

我的问题有点奇怪。我有四种方法(M1,M2,M3和M4),每种方法都在两个独立阶段(T1和T2)以及10种不同尺寸(1,2,...,10)中进行了实验。下表显示了数据的结构:在ggplot2中混合facet_grid()和facet_wrap()

 
phase size mean  stdev method 
T1 1  0.005  0.001 M1 
T1 2  0.009  0.004 M1 
T1 3  0.011  0.004 M1 
... 
T2 9  269.020 12.003 M4 
T2 10 297.024 10.004 M4 

第一阶段结果(T1)的范围小于第二阶段的范围。下面的命令生成的第一个情节

p <- ggplot(ds, aes(x=size, y=mean, color=method)) 
     + geom_line() 
     + geom_smooth(aes(ymin=mean-stdev, ymax=mean+stdev), stat="identity") 
     + scale_x_discrete(breaks=1:10) 
     + labs(x="Size", y="Time in Seconds", fill="Method") 
     + theme(panel.margin=unit(0.5, "lines"), legend.position="none") 
     + facet_grid(method~phase, scales="free_y") 

结果: The use of facet_grid()
虽然下面的代码给出了第二个数字

p <- ggplot(ds, aes(x=size, y=mean, color=method)) 
     + geom_line() 
     + geom_smooth(aes(ymin=mean-stdev, ymax=mean+stdev), stat="identity") 
     + scale_x_discrete(breaks=1:10) 
     + labs(x="Size", y="Time in Seconds", fill="Method") 
     + theme(panel.margin=unit(0.5, "lines"), legend.position="none") 
     + facet_wrap(method~phase, ncol=2, scales="free_y") 

The use of facet_wrap()
现在的问题是“我怎样才能使用facet_grid()并强制y轴自由,类似于使用facet_wrap()?“或“如何将facet_wrap()的标签更改为与facet_grid()类似?”
预先感谢您

回答

1

编辑:字为他人报警后,OP使用但不包括数据在这个答案是行不通的低值足够的动态范围。

我不认为你可以做你想要facet_grid什么,但如果你愿意调剂m和t你可以在你的特定实现八九不离十:

ggplot(ds, aes(x=size, y=mean, color=method)) + geom_line() + 
    #geom_smooth(aes(ymin=mean-stdev, ymax=mean+stdev), stat="identity") + 
    scale_x_discrete(breaks=1:10) + 
    labs(x="Size", y="Time in Seconds", fill="Method") + 
    theme(panel.margin=unit(0.5, "lines"), legend.position="none") + 
    facet_grid(phase~method, scales="free_y") 

enter image description here

facet_grid中,Y尺度在行中是自由的,但不是列,所以通过重新定向您的刻面,我们可以将高幅度和低幅度值分隔到行上,以便逐行释放具有期望的效果。

相关问题