gpt4 book ai didi

r - 更改绘图颜色栏标题

转载 作者:行者123 更新时间:2023-12-04 11:04:34 25 4
gpt4 key购买 nike

我正在尝试更改绘图散点图中颜色栏的标题。

查看文档,这似乎应该是微不足道的。但是,我试过插入 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")
})

关于r - 更改绘图颜色栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37283165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com