使用Plotly创建虚线网格线。

huangapple go评论112阅读模式
英文:

Make dotted gridlines with plotly

问题

阅读Plotly文档时,我认为可以使用griddash来样式化网格线,使线条不是实线,而是点线(例如)。

但是,这不起作用(gridcolorgridwidth确实起作用,仅用于更好的可见性):

library(plotly)

d <- data.frame(x = LETTERS[1:3], y = c(13, 50, 97))

plot_ly(d) %>%
  add_trace(x = ~ x, y = ~ y, type = "bar") %>%
  layout(yaxis = list(griddash = "dot", gridwidth = 2, gridcolor = "red"))

使用Plotly创建虚线网格线。


手动添加stroke-dasharray会起作用:

使用Plotly创建虚线网格线。

这让我相信这是一个bug,应该报告给开发团队?

英文:

Reading the documentation of plotly I thought I can use griddash to style the gridlines such that the line is not solid but dotted (say).

However, this does not work (gridcolor and gridwidth do work and are here just for better visibility):

library(plotly)

d &lt;- data.frame(x = LETTERS[1:3], y = c(13, 50, 97))

plot_ly(d) %&gt;%
  add_trace(x = ~ x, y = ~ y, type = &quot;bar&quot;) %&gt;%
  layout(yaxis = list(griddash = &quot;dot&quot;, gridwidth = 2, gridcolor = &quot;red&quot;))

使用Plotly创建虚线网格线。


Manually adding stroke-dasharray would do the trick:

使用Plotly创建虚线网格线。

Which makes me believe that this is a bug and shoudl be filed as such?

答案1

得分: 2

以下是您要翻译的内容:

"The reason this argument (and several others) isn't working is due to the Plotly JS dependency. Right now the R package appears to still be using 2.11.1. Meanwhile, Plotly JS is on 2.22? 2.23?

If you want to be able to use this argument, this is one way you can make plotly work for you-- change the dependency.

BTW, I used 2.21 here, because I already use this chunk regularly. You can always capture the dependency URL for a newer version."

请注意,代码部分已被排除在外,只提供翻译的文本部分。

英文:

The reason this argument (and several others) isn't working is due to the Plotly JS dependency. Right now the R package appears to still be using 2.11.1. Meanwhile, Plotly JS is on 2.22? 2.23?

If you want to be able to use this argument, this is one way you can make plotly work for you-- change the dependency.

BTW, I used 2.21 here, because I already use this chunk regularly. You can always capture the dependency URL for a newer version.

library(htmltools)
library(plotly)

#----------- your code ------------
d &lt;- data.frame(x = LETTERS[1:3], y = c(13, 50, 97))

plot_ly(d) %&gt;%
  add_trace(x = ~ x, y = ~ y, type = &quot;bar&quot;) %&gt;%
  layout(yaxis = list(griddash = &quot;dot&quot;, gridwidth = 2, gridcolor = &quot;red&quot;))

#----------- added code -------------

# assign plot to object
plt &lt;- plotly::last_plot()   # !! function exists in multiple libraries

# create new Plotly JS dependency
newDep &lt;- htmlDependency(name = &quot;plotly-latest&quot;, 
                         version = &quot;2.21.1&quot;,     
                         src = list(href = &quot;https://cdn.plot.ly&quot;),
                         script = &quot;plotly-2.21.0.min.js&quot;)

# add that dependency to plot
plt$dependencies[[6]] &lt;- newDep

# see what you&#39;ve got
plt

使用Plotly创建虚线网格线。

huangapple
  • 本文由 发表于 2023年6月13日 16:25:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76463006.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定