[英]How to make a legend appear on plotly but not plot the associated points
不确定这个结果应该有什么好处,但你可以像这样禁用legendclick:
编辑:也可以没有onRender
library(plotly)
mtcars %>%
mutate(cyl = factor(cyl)) %>%
plot_ly() %>%
add_markers(x = ~mpg,
y = ~hp,
color = ~cyl,
colors = c("4" = "red", "6" = "green", "8" = "blue"), visible='legendonly') %>%
layout(legend=list(itemclick = FALSE, itemdoubleclick = FALSE))
library(htmlwidgets)
library(plotly)
js <- c(
"function(el, x){",
" el.on('plotly_legendclick', function() {",
" return false;",
" });",
" el.on('plotly_legenddoubleclick', function() {",
" return false;",
" });",
"}")
mtcars %>%
mutate(cyl = factor(cyl)) %>%
plot_ly() %>%
add_markers(x = ~mpg,
y = ~hp,
color = ~cyl,
colors = c("4" = "red", "6" = "green", "8" = "blue"), visible='legendonly') %>%
onRender(js)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.