如何限制各个方面的y轴?

时间:2015-10-27 00:02:35

标签: r ggplot2

ggplot(all,aes(year,val))+
  geom_line()+
  facet_wrap(~frame)+
  theme_bw()+
  theme(panel.grid.major = element_line(colour = "#808080"))

enter image description here

但是,我想在特定值处切断y轴。例如,应将上三个面(Csb,BSk,Dfbw)切割为0.2,以便更好地突出该线。 dfbe应截止为0.1,dfa应为0.3。我希望每个方面都有一个y轴,而不是所有方面都有1个y轴。我怎样才能做到这一点?我找不到这种性质的先前问题。另一种选择是手动完成。

dput(全部)

structure(list(frame = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L), .Label = c("Csb", "BSk", "Dfb(W)", "Dfb(E)", "Dfa", 
"Cfa"), class = "factor"), year = c(1991, 1992, 1993, 1994, 1995, 
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 
2007, 2008, 2009, 2010, 2011, 2012, 2013, 1991, 1992, 1993, 1994, 
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 1991, 1992, 1993, 
1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 1991, 1992, 
1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 1991, 
1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 
1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 
2013), val = c(0.026984126984127, 0.0276923076923077, 0.0383084577114428, 
0.0141355563610004, 0.084130488103998, 0.0573679713951207, 0.0912003014886, 
0.0430606518454565, 0.0280665280665281, 0.0617283950617284, 0.00664451827242525, 
0.0282051282051282, 0.0229132569558101, 0.0151607034566404, 0.0846845780565747, 
0.0407859078590786, 0.0279365079365079, 0.0255822159491884, 0.0188275566966196, 
0.00798319327731092, 0.0190502233160149, 0.0907258064516129, 
0.00363636363636364, 0.0552995391705069, 0.0384615384615385, 
0.0592039800995025, 0.0608614232209738, 0.062962962962963, 0.0443736488792809, 
0.0516810225062517, 0.025049439683586, 0.10026525198939, 0.123456790123457, 
0.0568475452196382, 0.0286057692307692, 0.0693802035152636, 0.0680243366570897, 
0.0671085335542668, 0.0773333333333333, 0.0379008746355685, 0.0490252293577982, 
0.00903342366757001, 0.0194805194805195, 0.0436340969300296, 
0.048, 0.0516129032258064, 0.100840336134454, 0.0346153846153846, 
0.035181236673774, 0.0374531835205993, 0.137777777777778, 0.0656108597285068, 
0.0945408244469203, 0.0332415420928403, 0.0876923076923077, 0.0582010582010582, 
0.0221483942414175, 0.0388663967611336, 0.086436170212766, 0.0206185567010309, 
0.045271629778672, 0.0880630630630631, 0.0315126050420168, 0.0515049090616449, 
0.0593849416755037, 0.0493506493506493, 0.095058061031596, 0.0803571428571428, 
0.0262626262626263, 0.0407307577118898, 0.038966438966439, 0.0431537962362102, 
0.0694007490636704, 0.0222800925925926, 0.0554432779496718, 0.0601092896174863, 
0.0797696836384809, 0.0424363740348871, 0.0796202293664223, 0.0670903461601136, 
0.0462315462315462, 0.0431024733840611, 0.0593086719223772, 0.0721633169805349, 
0.0834922010398614, 0.0669341894060995, 0.0450043004587156, 0.0552803728551424, 
0.0729591836734694, 0.0936736853931256, 0.0701013513513514, 0.0894814814814815, 
0.222371967654987, 0.195339929779764, 0.232928717408807, 0.161604374354016, 
0.132859128444117, 0.088855614973262, 0.113010115102895, 0.154317321768914, 
0.170182660149215, 0.223718668163113, 0.176356589147287, 0.194908350305499, 
0.103897198230461, 0.133843381679615, 0.112490357969317, 0.0981363636363636, 
0.151267399267399, 0.20459775849918, 0.245018332536267, 0.15833493558931, 
0.10840262928645, 0.143203883495146, 0.251811824539097, 0.317666460523603, 
0.325913192952299, 0.245202558635394, 0.346881176659129, 0.27537372147915, 
0.262208067940552, 0.239909078385453, 0.296280342278363, 0.327372044298114, 
0.385321884745183, 0.374478234943351, 0.35365741380104, 0.373983493601878, 
0.305211654371553, 0.36442430808628, 0.362983425414365, 0.40790273556231, 
0.270589722671476, 0.313974535971775, 0.236274509803922, 0.241879060469765, 
0.403614180478821, 0.263001232344298)), .Names = c("frame", "year", 
"val"), row.names = c(NA, -138L), class = "data.frame")

1 个答案:

答案 0 :(得分:2)

您可以使用scales参数,这样您就可以为每个方面设置单独的y-axes

ggplot(all,aes(year,val))+
  geom_line()+
  facet_wrap(~frame, scales='free_y')+
  theme_bw()+
  theme(panel.grid.major = element_line(colour = "#808080"))

enter image description here