Plotly R-无法调整配色栏的方向

发布于 2025-02-07 23:45:17 字数 1076 浏览 0 评论 0原文

我正在尝试在具有水平方向的配色栏的闪亮应用程序中创建一个散点图。基于我阅读

经过多次尝试和调整,我找不到一种使配色栏水平显示的方法。

任何帮助将不胜感激。

使用虹膜数据集的最小示例:

library(shiny)


ui <- fluidPage(
          plotlyOutput("Scatter")
)

server <- function(input, output) {

      ScatterPlot<-reactive({
        plot_ly(
                iris,
                type='scatter',
                mode='lines+markers'
            )%>%
            add_trace(
                x=~Sepal.Length, 
                y=~Sepal.Width,
                mode='markers',
                marker=list(
                  color=~Petal.Length,
                  coloraxis='coloraxis'
                        )
                )%>%
            layout(
                showlegend=FALSE,
                margin=list(b=50),
                coloraxis=list(
                 colorbar=list(
                   orientation="h"
                   )
                  )
                )
                   }
        )
      
      output$Scatter<-renderPlotly({ScatterPlot()})
}

shinyApp(ui = ui, server = server)

I am trying to create a scatterplot within a Shiny App that has a colorbar with a horizontal orientation. Based on my reading of the Plotly reference it appears that the orientation of a colorbar can be adjusted within Layout/Coloraxis/Colorbar by setting orientation="h".

After many attempts and tweaks I can not find a way to get the colorbar to be displayed horizontally.

Any help would be appreciated.

Minimal example using the iris dataset:

library(shiny)


ui <- fluidPage(
          plotlyOutput("Scatter")
)

server <- function(input, output) {

      ScatterPlot<-reactive({
        plot_ly(
                iris,
                type='scatter',
                mode='lines+markers'
            )%>%
            add_trace(
                x=~Sepal.Length, 
                y=~Sepal.Width,
                mode='markers',
                marker=list(
                  color=~Petal.Length,
                  coloraxis='coloraxis'
                        )
                )%>%
            layout(
                showlegend=FALSE,
                margin=list(b=50),
                coloraxis=list(
                 colorbar=list(
                   orientation="h"
                   )
                  )
                )
                   }
        )
      
      output$Scatter<-renderPlotly({ScatterPlot()})
}

shinyApp(ui = ui, server = server)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文