1

这个问题跟随这篇文章

我正在用 绘制一个福斯特图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)

我正在添加hoverover文字:

text.vec <- paste0(paste0("Factor: ",factors),"\n","Effect Size: ",effect.sizes,"\n","Effect Error: ",effect.errors,"\n","P-Value: ",p.values)

然后将其全部绘制出来:

yform <- list(categoryorder = "array",
              categoryarray = rev(factors),
              title="Factor",zeroline=F,showticklabels=T)

library(grDevices)
mycramp <- colorRamp(c("darkred","gray"))
mycolors <- rgb(mycramp(p.values),maxColorValue = 255)

library(plotly)

plot_ly() %>%
  colorbar(limits=c(0,1),len=0.4,title="P-Value",inherit=FALSE) %>%
  add_trace(type='scatter',mode="markers",y=~factors,x=~effect.sizes,text=~text.vec,hoverinfo="text",
            color=~p.values,colors=grDevices::colorRamp(c("darkred","gray")),
            error_x=list(array=effect.errors,color=mycolors),split=factors,showlegend=FALSE,marker=list(color=mycolors)) %>%
  layout(xaxis=list(title="Effect Size",zeroline=T,showticklabels=T),yaxis=yform)

给出:

在此处输入图像描述

所以颜色编码效果很好。但是,图中误差线的长度似乎与effect.errors. 例如:

> factors[7]
[1] "7:age"
> effect.sizes[7]
[1] -0.8721795
> effect.errors[7]
[1] 0.1324996

和:

> factors[11]
[1] "11:age"
> effect.sizes[11]
[1] -1.198534
> effect.errors[11]
[1] 0.8714454

但在图中,您会看到 的误差条7:age比 的长得多11:age

调用时是否缺少某些参数error_x function

4

0 回答 0