我正在尝试创建一个森林图,R plotly在其中我要通过相应的p值对效果大小(点)及其误差线进行颜色编码。
以下是玩具数据:
set.seed(1)
factors <- paste0(1:25,":age")
effect.sizes <- rnorm(25,0,1)
effect.errors <- abs(rnorm(25,0,1))
p.values <- runif(25,0,1)
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试的:
library(dplyr)
plotly::plot_ly(type='scatter',mode="markers",y=~factors,x=~effect.sizes,color=~p.values,colors=grDevices::colorRamp(c("darkred","gray"))) %>%
plotly::add_trace(error_x=list(array=effect.errors),marker=list(color=~p.values,colors=grDevices::colorRamp(c("darkred","gray")))) %>%
plotly::colorbar(limits=c(0,1),len=0.4,title="P-Value") %>%
plotly::layout(xaxis=list(title="Effect Size",zeroline=T,showticklabels=T),yaxis=list(title="Factor",zeroline=F,showticklabels=T))
Run Code Online (Sandbox Code Playgroud)
这给了我:
除了以下几点,这与我想要的非常接近:
trace下面的两个图例colorbarfactors任何的想法?