如何移除Plotly悬浮信息框中的线条与标记符号?
移除Plotly统一悬浮框中的线条与标记符号
针对这个问题,这里提供两种简单的解决方法:
方法1:清空轨迹名称
在plot_ly()的轨迹参数中添加name = "",统一悬浮框就不会显示对应轨迹的图例符号(线条+标记):
library(tidyverse) library(plotly) demand <- tibble(q = seq(0,100,by=2), wtp = 50 - q/2) plot_ly( demand, x = ~q, y = ~wtp, type = "scatter", mode = "lines+markers", text = ~paste(wtp), hoverinfo = "text", name = "" ) |> layout(hovermode = "y unified")
方法2:自定义悬浮模板
使用hovertemplate替代text和hoverinfo,直接定义悬浮框的显示内容,通过<extra></extra>标签隐藏默认的符号和名称:
library(tidyverse) library(plotly) demand <- tibble(q = seq(0,100,by=2), wtp = 50 - q/2) plot_ly( demand, x = ~q, y = ~wtp, type = "scatter", mode = "lines+markers", hovertemplate = "%{y}<extra></extra>" ) |> layout(hovermode = "y unified")
<extra></extra>的作用是清除悬浮框中默认附加的轨迹标识信息,只保留你指定的内容。
内容的提问来源于stack exchange,提问作者profj
相关产品推荐
相关产品推荐

