You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Plotly在RShiny中绘制水平漏斗图的问题求助

R Plotly 水平漏斗图修正方案

核心调整点

要生成水平漏斗图,仅需在add_trace函数中补充orientation = "h"参数即可,之前配置失效大概率是参数值填写错误、或参数未写到add_trace的配置项内。

修正后基础绘图代码

library(plotly)

fig <- plot_ly() 
fig <- fig %>%
  add_trace(
    type = "funnel",
    orientation = "h",
    y = c("网站访问", "下载", "潜在客户", "申请报价", "已发送账单"),
    x = c(39, 27.4, 20.6, 11, 2)
    ) 
fig <- fig %>% layout(yaxis = list(categoryarray = c("网站访问", "下载", "潜在客户", "申请报价", "已发送账单")))

fig

R Shiny 嵌入示例

如果需要把该图集成到Shiny应用中,可参考以下完整代码:

library(shiny)
library(plotly)

# UI定义
ui <- fluidPage(
  plotlyOutput("horizontal_funnel")
)

# 服务端逻辑
server <- function(input, output) {
  output$horizontal_funnel <- renderPlotly({
    fig <- plot_ly() 
    fig <- fig %>%
      add_trace(
        type = "funnel",
        orientation = "h",
        y = c("网站访问", "下载", "潜在客户", "申请报价", "已发送账单"),
        x = c(39, 27.4, 20.6, 11, 2)
      ) 
    fig <- fig %>% layout(yaxis = list(categoryarray = c("网站访问", "下载", "潜在客户", "申请报价", "已发送账单")))
    return(fig)
  })
}

# 启动应用
shinyApp(ui, server)

内容的提问来源于stack exchange,提问作者Sameer Qayyum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 18:27:02