簡體   English   中英

更改Plotly Colorbar標題

[英]Change Plotly Colorbar Title

我試圖在繪圖散點圖中更改顏色條的標題。

看一下文檔,看起來這應該是微不足道的。 但是,我嘗試將colorbar = list(title = "Typing Rate")插入到主要的plotly()代碼中,並將其輸入layout() ,如下所示。

我該如何自定義此標題?

library(dplyr)
library(shiny)
library(plotly)

df <- as.data.frame(list("UserID"=c(1,1,1,1,2,2,2,2), 
                          "Category"=c('A','A','B','B','A','A','B','B'),
                          "Rate"=c(2,3,5,6,8,6,7,1),
                          "x"=c(1,3,5,7,2,4,6,8),
                          "y"=c(1,3,5,7,2,4,6,8)
                    ))

ui <- (fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("userInput","Select User", sort(unique(df$UserID)),
                  selected=1),
      checkboxGroupInput("CategoryInput", "Select Category", sort(unique(df$Category)),
                         selected=c('A','B'))
    ),

    mainPanel(
      plotlyOutput("mainPlot")#,
    )
  )
))

server <- function(input, output, session) {

  # filter for both user and category
  filteredFull <- reactive({
      df %>% 
        filter(
          UserID == input$userInput,
          Category %in% input$CategoryInput
        )
  })

  output$mainPlot <- renderPlotly({
        plot_ly(data=filteredFull(), x=x, y=y,
                       color=Rate, size=Rate,
                       mode='markers') %>%
      layout(
        colorbar = list(title = "Typing Rate")
      )
  })
}

shinyApp(ui, server)

嘗試這個:

  output$mainPlot <- renderPlotly({     
    m <- list(
  colorbar = list(title = "Typing Rate")
)
        plot_ly(data=filteredFull(), x=x, y=y,
                       color=Rate, size=Rate,
                       mode="markers", marker=m)
  })

更新(使用plotly_4.7.1 )。 它也可以這樣做:

  output$mainPlot <- renderPlotly({     
        plot_ly(data=filteredFull(), x=x, y=y,
                       color=Rate, size=Rate,
                       mode="markers") %>% colorbar(title = "Typing Rate")
  })

我在javaScript中尋找它時最終到了這里。 我知道OP在R中要求它; 我想為那些想在JS中做同樣事情的人添加這個答案。

var plotData8kW = [{
       z: data8kW,
        hoverinfo:"z",
        colorbar:{
            //  len: 0.35, //Change size of bar
            title: 'Speed(RPM)<br\><br\>', //set title
            titleside:'top', //set postion
           //tickvals:[0,50,100],
            titlefont: {color: 'blue'} //title font color
          },
         type: 'heatmap',
         colorscale: enhancedScale,
         },
 ];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM