[英]Change Plotly Colorbar Title
I am trying to change the title of the colorbar in a plotly scatter plot. 我试图在绘图散点图中更改颜色条的标题。
Looking at the documentation, it seems this should be trivial. 看一下文档,看起来这应该是微不足道的。 However, I've tried inserting
colorbar = list(title = "Typing Rate")
into both the main plotly()
code, as well as piping it into layout()
, as below. 但是,我尝试将
colorbar = list(title = "Typing Rate")
插入到主要的plotly()
代码中,并将其输入layout()
,如下所示。
How can I customize this title? 我该如何自定义此标题?
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)
Try this: 尝试这个:
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)
})
Update (with plotly_4.7.1
). 更新(使用
plotly_4.7.1
)。 It could also be done that way: 它也可以这样做:
output$mainPlot <- renderPlotly({
plot_ly(data=filteredFull(), x=x, y=y,
color=Rate, size=Rate,
mode="markers") %>% colorbar(title = "Typing Rate")
})
I ended up here while looking for it in javaScript. 我在javaScript中寻找它时最终到了这里。 I know OP asked for it in R;
我知道OP在R中要求它; I am adding this answer for those who want to do the same in JS.
我想为那些想在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.