• 绘制森林图(R)


    #object: 绘制森林图
    #writer: mike
    #time: 2020.10.13
    
    
    #构造数据集
    
    names <- c("a","b","c","d","e","f","g","h","l","m");
    or <- c(0.9,2,0.3,0.4,0.5,1.3,2.5,1.6,1.9,1.1);
    lower <- c(0.75,1.79,0.18,0.2,0.38,1.15,2.41,1.41,1.66,0.97);
    upper <- c(1.05,2.11,0.42,0.6,0.62,1.45,2.59,1.79,2.14,1.23);
    sample <- c(450,420,390,400,470,390,400,388,480,460);
    factors <- c("risk","risk","protec","protec","protec","risk","risk","risk","risk","risk");
    
    #构造数据框
    data <- data.frame(names,or,lower,upper,sample,factors);
    
    #载入包
    library("ggplot2");
    
    #颜色无法设置,颜色的设置不需要使用foctor()函数,但是必须使用col 而不是colors或者colours,注意这里一旦设置了颜色,就会和下面的涂层重合不到一起
    #不知道为什么会这样,好像是如果加上颜色之后,那么就要对后加的数据进行分类,并分配颜色。
    p <- ggplot(data, aes(x=or, y=names));
    
    
    #如果在point这里设置颜色,只会改变点的颜色,而上面会改变,与某一个数据有关的所有图像的颜色
    p <- p + geom_point(size=3.6) + geom_errorbarh(aes(xmax=upper, xmin=lower, height=0.3)) + scale_x_continuous(limits=c(0.1,5), breaks=seq(0,5,0.5)) + geom_vline(aes(xintercept=1)) + xlab("oddRatio") + ylab("")
    
    #在图形中加入标签
    #x坐标
    lx <- c(rep(2.87,11));
    #y坐标
    ly <- c(11,10,9,8,7,6,5,4,3,2,1);
    
    #标签
    llab <- c("p value","0.01","0.01","0.01","0.01","0.01","0.01","0.01","0.01","0.01","0.05");
    #构建另一个数据框
    data1 <- data.frame(lx,ly,llab);
    p <- p + geom_text(data=data1, aes(x=lx,y=ly,label=llab))
    p

  • 相关阅读:
    控制TABLE的一些属性
    windows7中各个dll文件作用和用途
    left join on and与left join on where的区别
    号外,left join比连表语句快80倍
    JS跳转语句
    [jQuery,Dojo,MooTools]
    CYQ.Data 数据框架 V3.5 开源版本发布(源码提供下载)
    Scala开发小小总结
    性能测试工具原理与架构
    joomla1.5模块开发和插件开发详解带实例
  • 原文地址:https://www.cnblogs.com/zijidefengge/p/13812336.html
Copyright © 2020-2023  润新知