从图表条中删除文本
Delete text from bars of plotly chart
在下面的绘图条形图中,如何只保留 hoverinfo
并跳过条形内的文本?
library(plotly)
x <- c('Product A', 'Product B', 'Product C')
y <- c(20, 14, 23)
data <- data.frame(x, y)
fig <- plot_ly(
data = as.data.frame(data),
x = ~ x,
y = ~ y,
type = "bar",
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5))
,
text = paste(
"X :",
data$x,
"<br> Count of Issue :",
data$y
),
hoverinfo = "text"
)
fig
来自very long layout documentation 关于text
:
If trace hoverinfo
contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels.
所以,我们只需要传入参数hovertext
而不是text
。
fig <- plot_ly(
data = as.data.frame(data),
x = ~ x,
y = ~ y,
type = "bar",
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5))
,
hovertext = paste(
"X :",
data$x,
"<br> Count of Issue :",
data$y
),
hoverinfo = "text"
)
fig
在下面的绘图条形图中,如何只保留 hoverinfo
并跳过条形内的文本?
library(plotly)
x <- c('Product A', 'Product B', 'Product C')
y <- c(20, 14, 23)
data <- data.frame(x, y)
fig <- plot_ly(
data = as.data.frame(data),
x = ~ x,
y = ~ y,
type = "bar",
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5))
,
text = paste(
"X :",
data$x,
"<br> Count of Issue :",
data$y
),
hoverinfo = "text"
)
fig
来自very long layout documentation 关于text
:
If trace
hoverinfo
contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels.
所以,我们只需要传入参数hovertext
而不是text
。
fig <- plot_ly(
data = as.data.frame(data),
x = ~ x,
y = ~ y,
type = "bar",
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5))
,
hovertext = paste(
"X :",
data$x,
"<br> Count of Issue :",
data$y
),
hoverinfo = "text"
)
fig