根据Ploty R中的数据绘制置信区间

azpvetkf  于 2023-01-22  发布在  其他
关注(0)|答案(2)|浏览(139)

尝试在条形图上添加误差线。

library(plotly)
library(plyr)

year <- c("1993","1994","1995","1996")
incident <- c(123.2,489.2,281.3,892.1)
lower_int <- c(32.1,23.1,11.1,34.2)
upper_int <- c(45.3,43.5,25.6,59.0)
data <- data.frame(year, incident, lower_int, upper_int)

fig <- plot_ly(data, x = ~year, y = ~incident, type = 'bar',
        error_y = ~list(y_min = ~lower_int,
                        y_max = ~upper_int))

fig

这段代码只绘制条形图,但间隔并没有显示在条形图上。

b4lqfgs4

b4lqfgs41#

您可以使用arrayarrayminus并删除列表前面的~

fig <- plot_ly(data, x = ~year, y = ~incident, type = 'bar',
               error_y = list(
                 color = "black",
                 array = upper_int,
                 arrayminus = lower_int))

fig

wydwbb8l

wydwbb8l2#

请更新阵列代码,如下所示
数组=下限整数-上限整数

fig <- plot_ly(data, x = ~year, y = ~incident, type = 'bar',
               error_y = ~list(array=lower_int - upper_int, color = 'black'))

fig

相关问题