沁香阁茶行小梁姐 發表於 2022-5-12 08:58:47

R语言可视化开发forestplot根据分组设置不同颜色

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>分组设置颜色</li><li>给每行增加辅助线</li></ul></div><p class="maodian"></p><h2>分组设置颜色</h2>
<div class="jb51code"><pre class="brush:ruby;">library(forestplot)
fn &lt;- local({
i = 0
function(..., clr.line, clr.marker){
    i &lt;&lt;- i + 1
    if(i%%4==3){fpDrawNormalCI(..., clr.line = "#000000", clr.marker = "#00B9BF")} #4组中的第3组
    else if(i%%4==0){fpDrawNormalCI(..., clr.line = "#000000", clr.marker = "#C26EFF")} #4组中的第4组
    else if(i%%4==2 ){fpDrawNormalCI(..., clr.line = "#000000", clr.marker = "#6DA500")} #4组中的第2组
    else(fpDrawNormalCI(..., clr.line = "#000000", clr.marker = "#F9675C")) #4组中的第1组
}
})
tabletext=cbind(c("Outcomes",figure_2_data$Treatmeant),c("CI (95%OR)",figure_2_data$`OR (95% CI)*`),c("P Value", figure_2_data$P))
forestplot(labeltext=tabletext,graph.pos = 2,mean = c(NA,figure_2_data$OR),lower = c(NA,figure_2_data$Low),upper = c(NA,figure_2_data$High),boxsize = 0.5,
            txt_gp=fpTxtGp(label=gpar(cex=1.25),
                         ticks=gpar(cex=1.1),
                         xlab=gpar(cex = 1.2),
                         title=gpar(cex = 1.2)),zero = 1,align = "l",
         is.summary = c(T,T,F,F,F,F,T,F,F,F,F,T,F,F,F,F,T,F,F,F,F),
         col = fpColors(box = c("darkblue","darkred")),
         fn.ci_norm = fn,
         colgap = unit(8,"mm"),
         graphwidth = unit(12,"cm")
         )
</pre></div>
<p>效果图</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202205/202205120852531.png" /></p>
<p class="maodian"></p><h2>给每行增加辅助线</h2>
<div class="jb51code"><pre class="brush:ruby;">line_list_Insuf1=list()
for (i in 1:84) {
exprs=paste0("line_list_Insuf1$`",i,"`=gpar(lwd=1, columns=1:5, col = '#99999922')")
eval(parse(text=exprs))
}
line_list_Insuf1$`1`=gpar(lwd=2, columns=1:7, col = '#202020')
line_list_Insuf1$`2`=gpar(lwd=2, columns=1:7, col = '#202020')
# parse 将character转换为expression
# eval 执行 expression
# forestplot 函数里面再加上这句参数
hrzl_lines = line_list_Insuf1
</pre></div>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202205/202205120852532.png" /></p>
<p>以上就是R语言可视化开发forestplot根据分组设置不同颜色的详细内容,更多关于forestplot分组设置颜色的资料请关注琼殿技术社区其它相关文章!</p>
                           
                            <div class="art_xg">
                              <b>您可能感兴趣的文章:</b><ul><li>R语言绘制数据可视化小提琴图Violin&nbsp;plot&nbsp;with&nbsp;dot画法</li><li>R语言数据可视化绘图Dot&nbsp;plot点图画法示例</li><li>R语言数据可视化绘图Slope&nbsp;chart坡度图画法</li><li>R语言可视化存储矢量图实现方式</li><li>R语言数据可视化ggplot绘制置信区间与分组绘图技巧</li></ul>
                            </div>

                        </div>
                        <!--endmain-->
頁: [1]
查看完整版本: R语言可视化开发forestplot根据分组设置不同颜色