plot_ly()在悬停信息中显示两次color和y属性,而不是仅显示一次

daolsyd0  于 2023-07-31  发布在  其他
关注(0)|答案(1)|浏览(72)

我的数据:

df<-structure(list(`Hospital Region` = structure(1:8, levels = c("LA-Santa Barbara-Ventura", 
"Mid-Coastal", "North Coast-East Bay", "Northeastern", "Orange", 
"San Diego-Imperial", "Southern Central Valley", "Southern Inland"
), class = "factor"), Count = c(14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L)), class = "data.frame", row.names = c(NA, -8L))

字符串
问题在于,在HoverInfo中,医院区域显示两次,同时显示为colory

fig <- plot_ly(df, x = ~Count, y = ~`Hospital Region`, type = 'bar', orientation = 'h',color=~`Hospital Region`)
    
fig

6rqinv9w

6rqinv9w1#

您可以指定hoverinfo = "text",然后在text中指定要在悬停时显示的列。

library(plotly)

fig <- plot_ly(df, x = ~Count, y = ~`Hospital Region`, type = 'bar', 
               orientation = 'h',color=~`Hospital Region`, 
                hoverinfo = "text", text = ~`Hospital Region`)
fig

字符串


的数据

相关问题