R 绘图包括分类变量的优势比,上限和下限为95%CI

R 绘图包括分类变量的优势比,上限和下限为95%CI,r,plot,ggplot2,R,Plot,Ggplot2,我正在研究农场管理实践在疾病预防方面的效果 关于如何在R中创建显示95%的变量优势比的绘图的任何帮助。自变量代码为0=农场未实施,1=实施。Orf.no.Orf.2012.2014为因变量,0=无疾病,1=存在疾病。提前谢谢 以下是数据样本和部分输出: Vet.Advice Quarantine Purchase.History Orf.no.Orf.2012.2014 1 1 2 1 0 0

我正在研究农场管理实践在疾病预防方面的效果

关于如何在R中创建显示95%的变量优势比的绘图的任何帮助。自变量代码为0=农场未实施,1=实施。Orf.no.Orf.2012.2014为因变量,0=无疾病,1=存在疾病。提前谢谢

以下是数据样本和部分输出:

Vet.Advice  Quarantine  Purchase.History Orf.no.Orf.2012.2014   
1           1           2                1  
0           0           0                1  
1           0           0                1  
0           0           0                1  
0           0           1                0  
1           0           0                1  
0           0           0                1  
0           1           0                1  
1           1           0                1  
0           0           1                1  
0           1           2                1  
0           0           0                1  


                             OR      2.5 %     97.5 %
(Intercept)               3.8251348 1.37283503 12.4437518
Footbath1                 1.7367032 0.91826113  3.3476932
Handwashing1              0.7927673 0.27360243  2.0484978
Handgels1                 1.4887936 0.58547658  4.3287735
Clean.Needles1            0.4719316 0.23958494  0.9120537
Vet.Vacc.Advice1          0.8666398 0.42396797  1.8096052
Disinfect.Trough1         0.7122465 0.36323418  1.3935948
Quarantine1               1.0648841 0.52899720  2.1936099
Quarantine2               0.2801078 0.06141656  1.1778524
Purchase.Disease.History1 0.5648420 0.26631744  1.1974933
Purchase.Disease.History2 0.4856445 0.13433826  1.7068997
给你

library(ggplot2)

#reading in data. You should be able
#to get this from your model by doing something like
#model_data <- exp(cbind(coef(model),confint(model)))
model_data <- read.table(text="
                                                     OR      2.5%     97.5%
(Intercept)               3.8251348 1.37283503 12.4437518
                         Footbath1                 1.7367032 0.91826113  3.3476932
                         Handwashing1              0.7927673 0.27360243  2.0484978
                         Handgels1                 1.4887936 0.58547658  4.3287735
                         Clean.Needles1            0.4719316 0.23958494  0.9120537
                         Vet.Vacc.Advice1          0.8666398 0.42396797  1.8096052
                         Disinfect.Trough1         0.7122465 0.36323418  1.3935948
                         Quarantine1               1.0648841 0.52899720  2.1936099
                         Quarantine2               0.2801078 0.06141656  1.1778524
                         Purchase.Disease.History1 0.5648420 0.26631744  1.1974933
                         Purchase.Disease.History2 0.4856445 0.13433826  1.7068997",
                         header=T)



#do some rearranging/renaming
colnames(model_data) <- c("OR","lower","upper")
model_data$variable <- rownames(model_data)

#plot without intercept (generally not reported)
p1 <- ggplot(model_data[-1,], aes(y=variable)) +
  geom_point(aes(x=OR)) + #plot OR
  geom_segment(aes(x=lower,xend=upper,yend=variable)) #plot confint

#add line for OR = 1
p1 <- p1 + geom_vline(xintercept=1) + theme_bw()
p1
库(ggplot2)
#读取数据。你应该能
#要从您的模型中获取此信息,请执行以下操作

#model_data您自己已经尝试过什么?@Heroka,尝试过阅读我遇到的一些代码,似乎更接近我上面给出的数据示例。由于这不是一个代码编写服务,我将给您一些提示,而不是为您编写代码。第一步是在数据帧中获取outputdata,其中一列指示变量,每个变量一行(您已经非常接近了)。然后,您可以使用变量为y的ggplot、OR的geom_点和置信区间的geom_段绘制该数据。thanks@Heroka不走运地试过你的小费。仍在学习编码和计数方面能力不足,遇到与我的问题/问题类似的链接。即使在基本代码完成时也能提供帮助。但作为对未来的建议:如果你在理解这些提示时遇到困难,那么在R中你有很多东西需要学习。做一些教程。因此,对于那些试图(并说明他们为什么错了)解决自己问题的人,他们通常会做出更好的反应。谢谢@Heroka,真的很有帮助。我已经记下你的建议了,不客气。我不是自吹自擂,但如果你满意,请接受答案(在投票按钮下打勾)。阻止其他人在这个问题上花费时间。