使用ggplot在facet_wrap中绘制多个模型

时间:2016-09-05 10:49:55

标签: r ggplot2 facet-wrap

我在facet_wrap中使用ggplot创建了一个多面板图,以及FlexParamCurve包中的模型输出。

FlexParamCurve提供了一个模型来拟合每组数据,即图中的每个面板。我在其他地方找到了代码,用于在所有面板上绘制相同的曲线,并绘制每个面板中各个线的模型曲线。但是,我如何绘制每个特定图的模型曲线?

样本数据;

DATA <- data.frame(Cond = rep(1:2, each = 60),
                   Site = rep((seq(1:2)), each = 30),
                   Survey = rep((seq(1:5)), each = 6),
                   Time = rep(1:6))

NUMBERS <- data.frame(Numbers = c(10,13,10,16,31,25,4,11,11,16,21,23,7,12,15,18,20,19,9,15,22,21,24,30,5,10,15,21,21,24,5,7,10,12,20,17,7,11,17,25,27,34,4,9,13,18,23,28,11,15,17,20,21,25,9,18,21,24,21,30,10,11,8,15,20,17,2,6,5,13,14,15,7,9,13,23,28,25,8,13,17,20,24,24,10,10,15,19,23,26,1,2,5,10,17,18,1,3,5,8,15,19,1,8,14,18,26,27,4,9,17,23,25,23,6,12,15,17,20,23))

GRAPH.DATA <- data.frame(cbind(DATA, NUMBERS))

ggplot代码;

ggplot(GRAPH.DATA, aes(Time, Numbers, colour=factor(Survey))) +
       geom_line(aes(group = Survey), size = 1.5) +
       facet_grid(Cond ~ Site)

FlexParamCurve代码和模型输出;

MODELS <- pn.mod.compare(GRAPH.DATA$Time, GRAPH.DATA$Numbers, GRAPH.DATA$Site, pn.options ="MOD.OUTPUTS")

Call:
Model: y ~ SSposnegRichards(x, Asym = Asym, K = K, Infl = Infl, M = M,
RAsym = RAsym, modno = 11, pn.options = "MOD.OUTPUTS") | grp 
Data: userdata 

Coefficients:
      Asym         K     Infl          M       RAsym
1-1  24.32301 1.0579649 35.61585  17.961961  -8.1278653
1-2  25.15115 0.4167590 31.70722   6.473804 -14.2503569
2-1  23.69160 0.9179826 36.32567  15.839351 -11.2709848
2-2  24.75980 0.3559937 35.14258   4.499553 -14.4040608

FlexParamCurve调用的格式为(x, y, grouping variable, output_object)

0 个答案:

没有答案