gpt4 book ai didi

javascript - R plotly : How to use config() in conjunction with plotly_build()?

转载 作者:行者123 更新时间:2023-11-29 16:08:39 30 4
gpt4 key购买 nike

运行代码直到并包括 plotly_build(p) 和正确的绘图结果。

可重现代码

library(plotly)

#data
df1 <- data.frame(cond = factor( rep(c("A","B"), each=200) ),
rating = c(rnorm(200),rnorm(200, mean=.8)))

df2 <- data.frame(x=c(.5,1),cond=factor(c("A","B")))

#plot
gg <- ggplot(data=df1, aes(x=rating, fill=cond)) +
geom_vline(aes(xintercept=mean(rating, na.rm=T))
, color="red", linetype="dashed", size=1, name="average") +
geom_vline(aes(xintercept=median(rating, na.rm=T))
, color="blue", linetype="dashed", size=1, name="median", yaxt="n") +
geom_histogram(binwidth=.5, position="dodge")

#create plotly object
p <- plotly_build(gg)

#append additional options to plot object
p$data[[1]]$hoverinfo <- "name+x" #hover options for 'average'
p$data[[2]]$hoverinfo <- "name+x" #hover options for 'median'

#display plot
plotly_build(p)
config(displayModeBar = F, showLink = F) # comment this line/config(.. out to get the plot

问题

我想使用config 更改一些设置。但是,config() 的使用似乎覆盖了 hoverinfo 更改。

在运行配置之前( plotly 应该如何)...

enter image description here

然后在运行 config(displayModeBar = F, showLink = F)...

enter image description here

最后,我尝试在 hoverinfo 行之前运行配置:

#create plotly object
p <- plotly_build(gg)
config(p=p,displayModeBar = F, showLink = F) #run config before 'hoverinfo' changes

#append additional options to plot object
p$data[[1]]$hoverinfo <- "name+x" #hover options for 'average'
p$data[[2]]$hoverinfo <- "name+x" #hover options for 'median'

#display plot
plotly_build(p)

但是,config 设置似乎被 displayModeBar 的返回覆盖(下面的屏幕截图):

enter image description here

最佳答案

添加最后一行 config 对我有用:

p <- plotly_build(gg)

p$data[[1]]$hoverinfo <- "name+x" #hover options for 'average'
p$data[[2]]$hoverinfo <- "name+x" #hover options for 'median'

p$config <- list(displayModeBar = F, showLink = F)

源自源代码。

更新

至少从 Plotly 版本 4.5.6 开始,config 现在是 Plotly 对象的 x 属性的一部分。该行应为:

p$x$config <- list(displayModeBar = F, showLink = F)

关于javascript - R plotly : How to use config() in conjunction with plotly_build()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34328259/

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