Cowplot中的plot_clone错误 [英] plot_clone error in cowplot

查看:123
本文介绍了Cowplot中的plot_clone错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在cowplot软件包中使用plot_grid进行2x2绘图.我不断收到错误消息:

I am trying to use plot_grid in package cowplot to make a 2x2 plot. I keep getting the error message:

plot_clone(plot)中的错误:尝试应用非功能

Error in plot_clone(plot) : attempt to apply non-function

而且我不知道如何解决这个问题.最初,我不确定Cowplot是否只能处理1x2或2x1布局,类似于您在

And I can't figure out how to correct this. At first I wasn't sure if cowplot could only handle 1x2 or 2x1 layouts, similar to what you see in this vignette. So, following the example near the end, I tried to save two pairs of two to then stack using plot_grid. But whenever I run that function, I get the same error message.

我的四个ggplots保存为:

My four ggplots are saved as:

> 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代码如下:

My code for the cowplot is as follows:

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运行的.

Has anyone run into and solved this issue before? Just to be sure I had all the system requirements correct, I updated to R version 3.3.1, which I am running from RStudio on a Windows 10 machine.

编辑

您应该能够复制&将此代码粘贴到控制台.这将创建我的四个数据框,将它们另存为ggplots,然后执行plot_grid.单独运行四个ggplots时,它们可以正常工作.

You should be able to just copy & paste this code to your console. This creates my four data frames, saves them as ggplots, and executes the plot_grid. The four ggplots work fine when you run them independently.

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排列它们之前.

I also just realized, when I go back and try to visualize just one of the plots (say, plot.b), that I am now receiving the error message and cannot generate it, whereas each plot was working fine on its own before trying to arrange them using plot_grid.

推荐答案

此代码:

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(cowplot)

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)

theme_set(theme_cowplot(font_size=12)) # reduce default font size
plot_grid(plot.a, plot.b, plot.c, plot.def, labels="AUTO")

生成以下输出:

我不知道你为什么遇到问题.

I don't know why you're having problems.

这是我正在使用的软件包:

Here are the packages I'm using:

> getRversion()
[1] ‘3.3.1’
> packageVersion("ggplot2")
[1] ‘2.1.0’
> packageVersion("cowplot")
[1] ‘0.6.3’

请注意,在您粘贴的最后一个代码示例中,您写的是require(gglot2)而不是require(ggplot2),这可能解释了您遇到的一些问题.另外,也不必分别要求cowplotggplot2cowplot将加载ggplot2.

Please note that in the last code example you pasted, you wrote require(gglot2) instead of require(ggplot2), which may explain some issues you had. Also, it's not necessary to require cowplot and ggplot2 separately, cowplot will load ggplot2.

这篇关于Cowplot中的plot_clone错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆