【发布时间】:2015-01-12 19:51:05
【问题描述】:
我的数据框示例如下:
ent corp smb fit se.fit UL LL PredictedProb 1 0 0 -2.54 0.10 0.087 0.06 0.072 0 0 1 -3.71 0.05 0.026 0.02 0.023 0 1 0 -3.60 0.05 0.029 0.02 0.026 1 0 0 -2.54 0.10 0.087 0.060 0.072 0 0 1 -3.71 0.05 0.026 0.021 0.023
我想制作 3 个图,根据预测概率为每个二进制 (sent,corp,smb) 绘制一条最佳拟合线 - 如果可能的话,我还想为预测概率添加点。到目前为止,我已经能够创建 3 个单独的地块,但我想将所有三个地块放在一个地块上。以下是我目前所拥有的:
这是 Corp 情节的代码:
corp.line <- ggplot(newdata3, aes(corp,PredictedProb))
corp.line <- corp.line + stat_smooth(method = "glm")
corp.line
这是 SMB 图的代码:
smb.line <- ggplot(newdata3, aes(smb,PredictedProb))
smb.line <- smb.line + stat_smooth(method = "glm")
smb.line
这是 Ent 图的代码:
ent.line <- ggplot(newdata3, aes(enterprise,PredictedProb))
ent.line <- ent.line + stat_smooth(method="glm",family= binomial(link="logit"))
ent.line
另外,在上一个图中,我无法使用 stat_smooth(method = "glm") 围绕最佳拟合线绘制平滑曲线。我还必须添加 family = binomial(link="logit")。有谁知道为什么会这样。
重申一下,我的主要问题是如何将所有这三个都绘制在一个情节上,而不必将它们分开。另外,我想为预测概率加分。
请代表我原谅任何不当行为。我对堆栈交换和 ggplot2 还是很陌生。
【问题讨论】:
-
stackoverflow.com/questions/21192002/… 可能有助于解决这个问题
-
@ckluss 感谢您的链接!虽然没有解决我的问题,但是对于如何组合情节真的很有帮助。
标签: r ggplot2 regression logistic-regression