我正在尝试plot_grid
在包 cowplot 中使用来制作 2x2 绘图。我不断收到错误消息:
plot_clone(plot) 中的错误:尝试应用非函数
我不知道如何纠正这个问题。起初我不确定 cowplot 是否只能处理 1x2 或 2x1 布局,类似于您在这个小插图中看到的。因此,按照接近结尾的示例,我尝试保存两对两个,然后使用plot_grid
. 但是每当我运行该函数时,我都会收到相同的错误消息。
我的四个ggplots保存为:
> dput(plot.a)
structure(list(data = structure(list(bin = structure(1:20, .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20"), class = "factor"),
dist = c(2.72727272727273, 18.3333333333333, 29.53125, 39.1025641025641,
49.5, 60, 69.6666666666667, 79.0606060606061, 89.6428571428571,
100, 107.5, 117.888888888889, 129.047619047619, 140, 149.782608695652,
160, 168.75, 177.083333333333, 187.5, 200), std.dist = c(-1.60612893947445,
-1.30910466744194, -1.09597893826813, -0.913811722884859,
-0.715921242615852, -0.516078698423106, -0.332096673610737,
-0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245,
1.00653116209305, 1.19271986786269, 1.38718362722209, 1.55371908071605,
1.71232427451981, 1.91058076677452, 2.14848855748017), obs = c(0.268181818181818,
0.425238095238095, 0.6328125, 0.546666666666667, 0.80125,
0.832068965517241, 0.906666666666667, 0.874848484848485,
0.764285714285714, 0.916458333333333, 1, 0.944444444444444,
1, 1, 1, 1, 1, 1, 1, 1), mpred = c(0.388774380495604, 0.497341593391953,
0.576647257194245, 0.641695739818402, 0.706912458033573,
0.76509928057554, 0.810878009592326, 0.848307082818594, 0.882946297247916,
0.909850599520384, 0.925472961630695, 0.943115230038192,
0.95758533934757, 0.968299080735412, 0.975544279359121, 0.981373141486811,
0.985217775779377, 0.988151202371436, 0.991013928856914,
0.993559472422062), lci = c(0.297768163760385, 0.42059410960659,
0.513948103151847, 0.587648581250763, 0.661468391191498,
0.723357484486191, 0.771582331828126, 0.809426276300194,
0.844627676773232, 0.872452498570834, 0.890204994397078,
0.911051522523887, 0.928724877550503, 0.942952498677686,
0.953383038475471, 0.9621, 0.96835, 0.973446874467174, 0.9786,
0.9836), uci = c(0.483767440722556, 0.573009143094962, 0.637484434181386,
0.691293140690589, 0.748919499311025, 0.804142486045091,
0.84934716439577, 0.885493777505561, 0.917754641498512, 0.940889978796971,
0.95374749869264, 0.967985138386314, 0.978485593963806, 0.985347498734588,
0.989613043478261, 0.9928, 0.99475, 0.996091666666667, 0.99735,
0.9983), x = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
110, 120, 130, 140, 150, 160, 170, 180, 190)), .Names = c("bin",
"dist", "std.dist", "obs", "mpred", "lci", "uci", "x"), row.names = c(NA,
-20L), class = "data.frame"), layers = list(<environment>, <environment>,
<environment>, <environment>, <environment>), scales = <S4 object of class structure("Scales", package = "ggplot2")>,
mapping = structure(list(x = x), .Names = "x", class = "uneval"),
theme = list(), coordinates = structure(list(limits = structure(list(
x = NULL, y = NULL), .Names = c("x", "y"))), .Names = "limits", class = c("cartesian",
"coord")), facet = structure(list(shrink = TRUE), .Names = "shrink", class = c("null",
"facet")), plot_env = <environment>, labels = structure(list(
x = "x", ymin = "lci", ymax = "uci", y = "uci"), .Names = c("x",
"ymin", "ymax", "y"))), .Names = c("data", "layers", "scales",
"mapping", "theme", "coordinates", "facet", "plot_env", "labels"
), class = c("gg", "ggplot"))
> dput(plot.b)
structure(list(data = structure(list(bin = structure(1:20, .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20"), class = "factor"),
dist = c(2.72727272727273, 18.3333333333333, 29.53125, 39.1025641025641,
49.5, 60, 69.6666666666667, 79.0606060606061, 89.6428571428571,
100, 107.5, 117.888888888889, 129.047619047619, 140, 149.782608695652,
160, 168.75, 177.083333333333, 187.5, 200), std.dist = c(-1.60612893947445,
-1.30910466744194, -1.09597893826813, -0.913811722884859,
-0.715921242615852, -0.516078698423106, -0.332096673610737,
-0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245,
1.00653116209305, 1.19271986786269, 1.38718362722209, 1.55371908071605,
1.71232427451981, 1.91058076677452, 2.14848855748017), obs = c(0.0909090909090909,
0.0985714285714286, 0.0315625, 0.0751282051282051, 0.028,
0.0293103448275862, 0.0333333333333333, 0.0106060606060606,
0.0714285714285714, 0.00229166666666667, 0, 0.00277777777777778,
0, 0, 0, 0, 0, 0, 0, 0), mpred = c(0.276177265460359, 0.209974580335731,
0.170205040967226, 0.141375628420341, 0.114888871702638,
0.0927755035971223, 0.0760669632294165, 0.0626412070343725,
0.0502322659015645, 0.0404643884892086, 0.0346603179456435,
0.0279245502708944, 0.022160834913022, 0.0176743725019984,
0.014473212195461, 0.0117578479216627, 0.00986488669064748,
0.00834929563349321, 0.0067862803157474, 0.00529717246203038
), lci = c(0.19062270150336, 0.15350824203276, 0.128925694286612,
0.10867300133109, 0.0871838636807364, 0.0670572349380336,
0.0515046182196629, 0.0387239876334207, 0.0279709435078909,
0.0199986096822199, 0.0157738436198193, 0.0112862759966146,
0.00792105787263693, 0.00547476100484075, 0.00395829271888495,
0.00278909928468121, 0.00209050333490606, 0.00158626547219278,
0.00111889275856179, 0.000737468674285579), uci = c(0.37243545256885,
0.272010803390763, 0.214473820819953, 0.17632268171621, 0.144964749207079,
0.120647489665425, 0.103803165916785, 0.0900475004082622,
0.0768597211395678, 0.0657889969676395, 0.0593651891164288,
0.05140562965974, 0.0440479874047032, 0.0374547496671013,
0.0326573463604563, 0.0283994982438483, 0.0249099236720525,
0.0220907957583452, 0.0190463443547909, 0.01613), x = c(0,
10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140,
150, 160, 170, 180, 190)), .Names = c("bin", "dist", "std.dist",
"obs", "mpred", "lci", "uci", "x"), row.names = c(NA, -20L), class = "data.frame"),
layers = list(<environment>, <environment>, <environment>,
<environment>, <environment>), scales = <S4 object of class structure("Scales", package = "ggplot2")>,
mapping = structure(list(x = x), .Names = "x", class = "uneval"),
theme = list(), coordinates = structure(list(limits = structure(list(
x = NULL, y = NULL), .Names = c("x", "y"))), .Names = "limits", class = c("cartesian",
"coord")), facet = structure(list(shrink = TRUE), .Names = "shrink", class = c("null",
"facet")), plot_env = <environment>, labels = structure(list(
x = "x", ymin = "lci", ymax = "uci", y = "uci"), .Names = c("x",
"ymin", "ymax", "y"))), .Names = c("data", "layers", "scales",
"mapping", "theme", "coordinates", "facet", "plot_env", "labels"
), class = c("gg", "ggplot"))
> dput(plot.c)
structure(list(data = structure(list(bin = structure(1:20, .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20"), class = "factor"),
dist = c(2.72727272727273, 18.3333333333333, 29.53125, 39.1025641025641,
49.5, 60, 69.6666666666667, 79.0606060606061, 89.6428571428571,
100, 107.5, 117.888888888889, 129.047619047619, 140, 149.782608695652,
160, 168.75, 177.083333333333, 187.5, 200), std.dist = c(-1.60612893947445,
-1.30910466744194, -1.09597893826813, -0.913811722884859,
-0.715921242615852, -0.516078698423106, -0.332096673610737,
-0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245,
1.00653116209305, 1.19271986786269, 1.38718362722209, 1.55371908071605,
1.71232427451981, 1.91058076677452, 2.14848855748017), obs = c(0.136363636363636,
0.224285714285714, 0.1746875, 0.180769230769231, 0.08, 0.0524137931034483,
0.06, 0.0918181818181818, 0.128571428571429, 0.08125, 0,
0.0527777777777778, 0, 0, 0, 0, 0, 0, 0, 0), mpred = c(0.396007183344234,
0.323398427924327, 0.275767873201439, 0.23877806882699, 0.202648932853717,
0.170561630695444, 0.144888476951772, 0.123223719933144,
0.102255775950668, 0.0849707474020783, 0.074301175059952,
0.0615282629451994, 0.0501849880095923, 0.0410420743405276,
0.0343116945400202, 0.0284480003996803, 0.0242571770583533,
0.0208352824074074, 0.0172327575939249, 0.0137187533972822
), lci = c(0.309108383852639, 0.259739964454443, 0.226331084336736,
0.198126852675932, 0.168002492573431, 0.1387, 0.112832816960042,
0.090929302258261, 0.0707525118106233, 0.0546067388110001,
0.0456586166307923, 0.0349413825456728, 0.0259271742309591,
0.0193719588008097, 0.0149584265465208, 0.0113157400820788,
0.00895191986755036, 0.00713492400674309, 0.00532896603864423,
0.00377012376932766), uci = c(0.489901697647913, 0.391021582366999,
0.3273925733182, 0.281850059674837, 0.240157199858824, 0.2057,
0.180443166234289, 0.159109689350491, 0.1395, 0.1227, 0.111566091657504,
0.0979619976347301, 0.084907043339688, 0.0742617216260901,
0.0655689139953165, 0.0568322234548294, 0.0501718975901771,
0.0447513982066218, 0.0391577198298473, 0.0330701139149641
), x = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110,
120, 130, 140, 150, 160, 170, 180, 190)), .Names = c("bin",
"dist", "std.dist", "obs", "mpred", "lci", "uci", "x"), row.names = c(NA,
-20L), class = "data.frame"), layers = list(<environment>, <environment>,
<environment>, <environment>, <environment>), scales = <S4 object of class structure("Scales", package = "ggplot2")>,
mapping = structure(list(x = x), .Names = "x", class = "uneval"),
theme = list(), coordinates = structure(list(limits = structure(list(
x = NULL, y = NULL), .Names = c("x", "y"))), .Names = "limits", class = c("cartesian",
"coord")), facet = structure(list(shrink = TRUE), .Names = "shrink", class = c("null",
"facet")), plot_env = <environment>, labels = structure(list(
x = "x", ymin = "lci", ymax = "uci", y = "uci"), .Names = c("x",
"ymin", "ymax", "y"))), .Names = c("data", "layers", "scales",
"mapping", "theme", "coordinates", "facet", "plot_env", "labels"
), class = c("gg", "ggplot"))
> dput(plot.def)
structure(list(data = structure(list(bin = structure(1:20, .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20"), class = "factor"),
dist = c(2.72727272727273, 18.3333333333333, 29.53125, 39.1025641025641,
49.5, 60, 69.6666666666667, 79.0606060606061, 89.6428571428571,
100, 107.5, 117.888888888889, 129.047619047619, 140, 149.782608695652,
160, 168.75, 177.083333333333, 187.5, 200), std.dist = c(-1.60612893947445,
-1.30910466744194, -1.09597893826813, -0.913811722884859,
-0.715921242615852, -0.516078698423106, -0.332096673610737,
-0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245,
1.00653116209305, 1.19271986786269, 1.38718362722209, 1.55371908071605,
1.71232427451981, 1.91058076677452, 2.14848855748017), obs = c(0.504545454545455,
0.251904761904762, 0.1609375, 0.197435897435897, 0.09075,
0.0862068965517241, 0, 0.0227272727272727, 0.0357142857142857,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), mpred = c(0.545319024780176,
0.385214215294431, 0.281065328986811, 0.207366167578758,
0.14471123461231, 0.098486518784972, 0.0684568028244071,
0.047804470120873, 0.0316512625042823, 0.0211158213429257,
0.0158420865307754, 0.0105729330246914, 0.00686132620379887,
0.00449120627498002, 0.00309464743440031, 0.0020996685891287,
0.0015159548421263, 0.00111107593891553, 0.00075490557773781,
0.000474568535971223), lci = c(0.417808749228615, 0.297629056710751,
0.221329055036562, 0.15937986030437, 0.10455, 0.0642914930179108,
0.0397254303811289, 0.0241381409954533, 0.013732639580488,
0.00773819374865001, 0.00515355573824683, 0.00290910838994936,
0.00156671161936531, 0.000857607184772948, 0.000498446746117533,
0.000280876962784603, 0.000172977492684956, 0.000109686646512733,
6.20418685828108e-05, 3.07803199924385e-05), uci = c(0.671203738070494,
0.476831664841552, 0.345660702829477, 0.257423105479597,
0.186359497668321, 0.137389854806939, 0.102873333333333,
0.0774201540832578, 0.0559549705034255, 0.0411089951472052,
0.032910549513622, 0.0240294378945808, 0.017022668627324,
0.012113724270874, 0.00894324443701978, 0.00658660181431583,
0.00506777502183314, 0.00392338811324972, 0.00284237332468719,
0.00192574352635954), x = c(0, 10, 20, 30, 40, 50, 60, 70,
80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190)), .Names = c("bin",
"dist", "std.dist", "obs", "mpred", "lci", "uci", "x"), row.names = c(NA,
-20L), class = "data.frame"), layers = list(<environment>, <environment>,
<environment>, <environment>, <environment>), scales = <S4 object of class structure("Scales", package = "ggplot2")>,
mapping = structure(list(x = x), .Names = "x", class = "uneval"),
theme = list(), coordinates = structure(list(limits = structure(list(
x = NULL, y = NULL), .Names = c("x", "y"))), .Names = "limits", class = c("cartesian",
"coord")), facet = structure(list(shrink = TRUE), .Names = "shrink", class = c("null",
"facet")), plot_env = <environment>, labels = structure(list(
x = "x", ymin = "lci", ymax = "uci", y = "uci"), .Names = c("x",
"ymin", "ymax", "y"))), .Names = c("data", "layers", "scales",
"mapping", "theme", "coordinates", "facet", "plot_env", "labels"
), class = c("gg", "ggplot"))
我的cowplot代码如下:
require(cowplot)
theme_set(theme_cowplot(font_size=12)) # reduce default font size
top_row <- plot_grid(plot.a, plot.b, labels=c("A","B"))
bottom_row <-plot_grid(plot.c, plot.def, labels=c("C","D"))
plot_grid(top_row,bottom_row)
有没有人遇到过并解决过这个问题?为了确保我的所有系统要求都正确,我更新到 R 版本 3.3.1,我在 Windows 10 机器上从 RStudio 运行。
编辑
您应该能够将此代码复制并粘贴到您的控制台。这将创建我的四个数据框,将它们保存为 ggplots,然后执行 plot_grid。当您独立运行四个 ggplots 时,它们可以正常工作。
pd.a.agg <- structure(list(bin = structure(1:20, .Label = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20"), class = "factor"), dist = c(2.72727272727273,
18.3333333333333, 29.53125, 39.1025641025641, 49.5, 60, 69.6666666666667,
79.0606060606061, 89.6428571428571, 100, 107.5, 117.888888888889,
129.047619047619, 140, 149.782608695652, 160, 168.75, 177.083333333333,
187.5, 200), std.dist = c(-1.60612893947445, -1.30910466744194,
-1.09597893826813, -0.913811722884859, -0.715921242615852, -0.516078698423106,
-0.332096673610737, -0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245, 1.00653116209305,
1.19271986786269, 1.38718362722209, 1.55371908071605, 1.71232427451981,
1.91058076677452, 2.14848855748017), obs = c(0.268181818181818,
0.425238095238095, 0.6328125, 0.546666666666667, 0.80125, 0.832068965517241,
0.906666666666667, 0.874848484848485, 0.764285714285714, 0.916458333333333,
1, 0.944444444444444, 1, 1, 1, 1, 1, 1, 1, 1), mpred = c(0.388774380495604,
0.497341593391953, 0.576647257194245, 0.641695739818402, 0.706912458033573,
0.76509928057554, 0.810878009592326, 0.848307082818594, 0.882946297247916,
0.909850599520384, 0.925472961630695, 0.943115230038192, 0.95758533934757,
0.968299080735412, 0.975544279359121, 0.981373141486811, 0.985217775779377,
0.988151202371436, 0.991013928856914, 0.993559472422062), lci = c(0.297768163760385,
0.42059410960659, 0.513948103151847, 0.587648581250763, 0.661468391191498,
0.723357484486191, 0.771582331828126, 0.809426276300194, 0.844627676773232,
0.872452498570834, 0.890204994397078, 0.911051522523887, 0.928724877550503,
0.942952498677686, 0.953383038475471, 0.9621, 0.96835, 0.973446874467174,
0.9786, 0.9836), uci = c(0.483767440722556, 0.573009143094962,
0.637484434181386, 0.691293140690589, 0.748919499311025, 0.804142486045091,
0.84934716439577, 0.885493777505561, 0.917754641498512, 0.940889978796971,
0.95374749869264, 0.967985138386314, 0.978485593963806, 0.985347498734588,
0.989613043478261, 0.9928, 0.99475, 0.996091666666667, 0.99735,
0.9983), x = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110,
120, 130, 140, 150, 160, 170, 180, 190)), .Names = c("bin", "dist",
"std.dist", "obs", "mpred", "lci", "uci", "x"), row.names = c(NA,
-20L), class = "data.frame")
pd.b.agg <- structure(list(bin = structure(1:20, .Label = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20"), class = "factor"), dist = c(2.72727272727273,
18.3333333333333, 29.53125, 39.1025641025641, 49.5, 60, 69.6666666666667,
79.0606060606061, 89.6428571428571, 100, 107.5, 117.888888888889,
129.047619047619, 140, 149.782608695652, 160, 168.75, 177.083333333333,
187.5, 200), std.dist = c(-1.60612893947445, -1.30910466744194,
-1.09597893826813, -0.913811722884859, -0.715921242615852, -0.516078698423106,
-0.332096673610737, -0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245, 1.00653116209305,
1.19271986786269, 1.38718362722209, 1.55371908071605, 1.71232427451981,
1.91058076677452, 2.14848855748017), obs = c(0.0909090909090909,
0.0985714285714286, 0.0315625, 0.0751282051282051, 0.028, 0.0293103448275862,
0.0333333333333333, 0.0106060606060606, 0.0714285714285714, 0.00229166666666667,
0, 0.00277777777777778, 0, 0, 0, 0, 0, 0, 0, 0), mpred = c(0.276177265460359,
0.209974580335731, 0.170205040967226, 0.141375628420341, 0.114888871702638,
0.0927755035971223, 0.0760669632294165, 0.0626412070343725, 0.0502322659015645,
0.0404643884892086, 0.0346603179456435, 0.0279245502708944, 0.022160834913022,
0.0176743725019984, 0.014473212195461, 0.0117578479216627, 0.00986488669064748,
0.00834929563349321, 0.0067862803157474, 0.00529717246203038),
lci = c(0.19062270150336, 0.15350824203276, 0.128925694286612,
0.10867300133109, 0.0871838636807364, 0.0670572349380336,
0.0515046182196629, 0.0387239876334207, 0.0279709435078909,
0.0199986096822199, 0.0157738436198193, 0.0112862759966146,
0.00792105787263693, 0.00547476100484075, 0.00395829271888495,
0.00278909928468121, 0.00209050333490606, 0.00158626547219278,
0.00111889275856179, 0.000737468674285579), uci = c(0.37243545256885,
0.272010803390763, 0.214473820819953, 0.17632268171621, 0.144964749207079,
0.120647489665425, 0.103803165916785, 0.0900475004082622,
0.0768597211395678, 0.0657889969676395, 0.0593651891164288,
0.05140562965974, 0.0440479874047032, 0.0374547496671013,
0.0326573463604563, 0.0283994982438483, 0.0249099236720525,
0.0220907957583452, 0.0190463443547909, 0.01613), x = c(0,
10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140,
150, 160, 170, 180, 190)), .Names = c("bin", "dist", "std.dist",
"obs", "mpred", "lci", "uci", "x"), row.names = c(NA, -20L), class = "data.frame")
pd.c.agg <- structure(list(bin = structure(1:20, .Label = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20"), class = "factor"), dist = c(2.72727272727273,
18.3333333333333, 29.53125, 39.1025641025641, 49.5, 60, 69.6666666666667,
79.0606060606061, 89.6428571428571, 100, 107.5, 117.888888888889,
129.047619047619, 140, 149.782608695652, 160, 168.75, 177.083333333333,
187.5, 200), std.dist = c(-1.60612893947445, -1.30910466744194,
-1.09597893826813, -0.913811722884859, -0.715921242615852, -0.516078698423106,
-0.332096673610737, -0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245, 1.00653116209305,
1.19271986786269, 1.38718362722209, 1.55371908071605, 1.71232427451981,
1.91058076677452, 2.14848855748017), obs = c(0.136363636363636,
0.224285714285714, 0.1746875, 0.180769230769231, 0.08, 0.0524137931034483,
0.06, 0.0918181818181818, 0.128571428571429, 0.08125, 0, 0.0527777777777778,
0, 0, 0, 0, 0, 0, 0, 0), mpred = c(0.396007183344234, 0.323398427924327,
0.275767873201439, 0.23877806882699, 0.202648932853717, 0.170561630695444,
0.144888476951772, 0.123223719933144, 0.102255775950668, 0.0849707474020783,
0.074301175059952, 0.0615282629451994, 0.0501849880095923, 0.0410420743405276,
0.0343116945400202, 0.0284480003996803, 0.0242571770583533, 0.0208352824074074,
0.0172327575939249, 0.0137187533972822), lci = c(0.309108383852639,
0.259739964454443, 0.226331084336736, 0.198126852675932, 0.168002492573431,
0.1387, 0.112832816960042, 0.090929302258261, 0.0707525118106233,
0.0546067388110001, 0.0456586166307923, 0.0349413825456728, 0.0259271742309591,
0.0193719588008097, 0.0149584265465208, 0.0113157400820788, 0.00895191986755036,
0.00713492400674309, 0.00532896603864423, 0.00377012376932766
), uci = c(0.489901697647913, 0.391021582366999, 0.3273925733182,
0.281850059674837, 0.240157199858824, 0.2057, 0.180443166234289,
0.159109689350491, 0.1395, 0.1227, 0.111566091657504, 0.0979619976347301,
0.084907043339688, 0.0742617216260901, 0.0655689139953165, 0.0568322234548294,
0.0501718975901771, 0.0447513982066218, 0.0391577198298473, 0.0330701139149641
), x = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120,
130, 140, 150, 160, 170, 180, 190)), .Names = c("bin", "dist",
"std.dist", "obs", "mpred", "lci", "uci", "x"), row.names = c(NA,
-20L), class = "data.frame")
pd.def.agg <- structure(list(bin = structure(1:20, .Label = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20"), class = "factor"), dist = c(2.72727272727273,
18.3333333333333, 29.53125, 39.1025641025641, 49.5, 60, 69.6666666666667,
79.0606060606061, 89.6428571428571, 100, 107.5, 117.888888888889,
129.047619047619, 140, 149.782608695652, 160, 168.75, 177.083333333333,
187.5, 200), std.dist = c(-1.60612893947445, -1.30910466744194,
-1.09597893826813, -0.913811722884859, -0.715921242615852, -0.516078698423106,
-0.332096673610737, -0.153305364231945, 0.0481026338217207, 0.245226231834973,
0.387970906258363, 0.585698714533726, 0.798078621665245, 1.00653116209305,
1.19271986786269, 1.38718362722209, 1.55371908071605, 1.71232427451981,
1.91058076677452, 2.14848855748017), obs = c(0.504545454545455,
0.251904761904762, 0.1609375, 0.197435897435897, 0.09075, 0.0862068965517241,
0, 0.0227272727272727, 0.0357142857142857, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), mpred = c(0.545319024780176, 0.385214215294431,
0.281065328986811, 0.207366167578758, 0.14471123461231, 0.098486518784972,
0.0684568028244071, 0.047804470120873, 0.0316512625042823, 0.0211158213429257,
0.0158420865307754, 0.0105729330246914, 0.00686132620379887,
0.00449120627498002, 0.00309464743440031, 0.0020996685891287,
0.0015159548421263, 0.00111107593891553, 0.00075490557773781,
0.000474568535971223), lci = c(0.417808749228615, 0.297629056710751,
0.221329055036562, 0.15937986030437, 0.10455, 0.0642914930179108,
0.0397254303811289, 0.0241381409954533, 0.013732639580488, 0.00773819374865001,
0.00515355573824683, 0.00290910838994936, 0.00156671161936531,
0.000857607184772948, 0.000498446746117533, 0.000280876962784603,
0.000172977492684956, 0.000109686646512733, 6.20418685828108e-05,
3.07803199924385e-05), uci = c(0.671203738070494, 0.476831664841552,
0.345660702829477, 0.257423105479597, 0.186359497668321, 0.137389854806939,
0.102873333333333, 0.0774201540832578, 0.0559549705034255, 0.0411089951472052,
0.032910549513622, 0.0240294378945808, 0.017022668627324, 0.012113724270874,
0.00894324443701978, 0.00658660181431583, 0.00506777502183314,
0.00392338811324972, 0.00284237332468719, 0.00192574352635954
), x = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120,
130, 140, 150, 160, 170, 180, 190)), .Names = c("bin", "dist",
"std.dist", "obs", "mpred", "lci", "uci", "x"), row.names = c(NA,
-20L), class = "data.frame")
require(gglot2)
plot.a<-ggplot(pd.a.agg, aes(x=x)) +
geom_ribbon(aes(ymin=lci,ymax=uci), alpha=0.6, fill="grey70") +
geom_line(aes(y=uci), linetype=2) +
geom_line(aes(y=lci), linetype=2) +
geom_line(aes(y=mpred)) +
geom_point(aes(y=obs), size=3)
plot.b<-ggplot(pd.b.agg, aes(x=x)) +
geom_ribbon(aes(ymin=lci,ymax=uci), alpha=0.6, fill="grey70") +
geom_line(aes(y=uci), linetype=2) +
geom_line(aes(y=lci), linetype=2) +
geom_line(aes(y=mpred)) +
geom_point(aes(y=obs), size=3)
plot.c<-ggplot(pd.c.agg, aes(x=x)) +
geom_ribbon(aes(ymin=lci,ymax=uci), alpha=0.6, fill="grey70") +
geom_line(aes(y=uci), linetype=2) +
geom_line(aes(y=lci), linetype=2) +
geom_line(aes(y=mpred)) +
geom_point(aes(y=obs), size=3)
plot.def<-ggplot(pd.def.agg, aes(x=x)) +
geom_ribbon(aes(ymin=lci,ymax=uci), alpha=0.6, fill="grey70") +
geom_line(aes(y=uci), linetype=2) +
geom_line(aes(y=lci), linetype=2) +
geom_line(aes(y=mpred)) +
geom_point(aes(y=obs), size=3)
require(cowplot)
theme_set(theme_cowplot(font_size=12)) # reduce default font size
top_row <- plot_grid(plot.a, plot.b, labels=c("A","B"))
bottom_row <-plot_grid(plot.c, plot.def, labels=c("C","D"))
plot_grid(top_row,bottom_row)
编辑 2
我也刚刚意识到,当我返回并尝试仅可视化其中一个图(例如,plot.b)时,我现在收到错误消息并且无法生成它,而在尝试之前每个图都可以正常工作安排他们使用plot_grid
.