英文:
Make dotted gridlines with plotly
问题
阅读Plotly文档时,我认为可以使用griddash
来样式化网格线,使线条不是实线,而是点线(例如)。
但是,这不起作用(gridcolor
和gridwidth
确实起作用,仅用于更好的可见性):
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"))
手动添加stroke-dasharray
会起作用:
这让我相信这是一个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 <- 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"))
Manually adding stroke-dasharray
would do the trick:
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 <- 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"))
#----------- added code -------------
# assign plot to object
plt <- plotly::last_plot() # !! function exists in multiple libraries
# create new Plotly JS dependency
newDep <- htmlDependency(name = "plotly-latest",
version = "2.21.1",
src = list(href = "https://cdn.plot.ly"),
script = "plotly-2.21.0.min.js")
# add that dependency to plot
plt$dependencies[[6]] <- newDep
# see what you've got
plt
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论