gpt4 book ai didi

R plotly highlight_key 函数只突出显示了一半的栏

转载 作者:行者123 更新时间:2023-12-04 17:32:25 25 4
gpt4 key购买 nike

当我在 R 中使用 plotly 绘制具有点击突出显示功能的条形图时,只有一半的条形图被突出显示,可以通过以下脚本重现。

library(plotly)

D = data.frame(
NAME = LETTERS[1:5],
VALUE = rnorm(5)
)

D %>%
highlight_key(~NAME) %>%
plot_ly(x=~VALUE, y = ~NAME, type ="bar", orientation = "h") %>%
highlight(on = "plotly_click",off = "plotly_doubleclick")

我在 Rstudio 中可以看到的内容:

enter image description here

最佳答案

您可以通过添加 layout(barmode = "overlay") 来解决这个问题。

library(plotly)

D = data.frame(
NAME = LETTERS[1:5],
VALUE = rnorm(5)
)

D %>%
highlight_key(~NAME) %>%
plot_ly(x=~VALUE, y = ~NAME, type ="bar", orientation = "h") %>%
highlight(on = "plotly_click",off = "plotly_doubleclick") %>%
layout(barmode = "overlay")

enter image description here

或者,可以在 plot_ly 函数中使用 selectedpoints

关于R plotly highlight_key 函数只突出显示了一半的栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58162823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com