在Plotly漏斗图中使柱状条之间的区域透明化。

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

Make area between bars transparent in plotly funnel plot

问题

我想知道如何使用R中的plotly更改以下漏斗图中每个条之间区域的颜色。我已经阅读了plotly网站上的文档,但它只演示了如何格式化围绕区域的“线条”。我应该如何实际更改区域的颜色(以下图中浅蓝色的部分)?

以下是绘图的代码(这是plotly网站上的示例):

library(plotly)

fig <- plot_ly() 
fig <- fig %>%
  add_trace(
  type = "funnel",
  y = c("Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"),
  x = c(39, 27.4, 20.6, 11, 2)) 
fig <- fig %>%
  layout(yaxis = list(categoryarray = c("Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent")))

fig

在Plotly漏斗图中使柱状条之间的区域透明化。

英文:

I would like to know how to change the colour of the area in between each of the bars in the following funnel plot using plotly in R. I've read through the documentation on the plotly website, but it only demonstrates how to format the "lines" that outline the area. How do I actually change the colour of the area (the bits in light blue in the following plot)?

在Plotly漏斗图中使柱状条之间的区域透明化。

The code for the plot is below (this is the example on the plotly website):

library(plotly)

fig &lt;- plot_ly() 
fig &lt;- fig %&gt;%
  add_trace(
  type = &quot;funnel&quot;,
  y = c(&quot;Website visit&quot;, &quot;Downloads&quot;, &quot;Potential customers&quot;, &quot;Requested price&quot;, &quot;invoice sent&quot;),
  x = c(39, 27.4, 20.6, 11, 2)) 
fig &lt;- fig %&gt;%
  layout(yaxis = list(categoryarray = c(&quot;Website visit&quot;, &quot;Downloads&quot;, &quot;Potential customers&quot;, &quot;Requested price&quot;, &quot;invoice sent&quot;)))

fig

答案1

得分: 3

可以通过add_trace(connector = list(fillcolor))来设置。例如将其设置为"black":

library(plotly)

plot_ly() %>%
  add_trace(
    type = "funnel",
    y = c("Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"),
    x = c(39, 27.4, 20.6, 11, 2),
    connector = list(fillcolor = "black")) %>%
  layout(yaxis = list(categoryarray = c("Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"))))

在Plotly漏斗图中使柱状条之间的区域透明化。


如果透明意味着隐藏该区域,请使用visible = FALSE

plot_ly() %>%
  add_trace(
    type = "funnel",
    y = c("Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"),
    x = c(39, 27.4, 20.6, 11, 2),
    connector = list(visible = F)) %>%
  layout(yaxis = list(categoryarray = c("Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"))))

在Plotly漏斗图中使柱状条之间的区域透明化。

英文:

It can be set via add_trace(connector = list(fillcolor)), see reference here.

For example setting it to "black":

library(plotly)

plot_ly() %&gt;%
  add_trace(
    type = &quot;funnel&quot;,
    y = c(&quot;Website visit&quot;, &quot;Downloads&quot;, &quot;Potential customers&quot;, &quot;Requested price&quot;, &quot;invoice sent&quot;),
    x = c(39, 27.4, 20.6, 11, 2),
    connector = list(fillcolor = &quot;black&quot;)) %&gt;%
  layout(yaxis = list(categoryarray = c(&quot;Website visit&quot;, &quot;Downloads&quot;, &quot;Potential customers&quot;, &quot;Requested price&quot;, &quot;invoice sent&quot;)))

在Plotly漏斗图中使柱状条之间的区域透明化。

<hr>

If transparent meant hiding the area, use visible = FALSE.

plot_ly() %&gt;%
  add_trace(
    type = &quot;funnel&quot;,
    y = c(&quot;Website visit&quot;, &quot;Downloads&quot;, &quot;Potential customers&quot;, &quot;Requested price&quot;, &quot;invoice sent&quot;),
    x = c(39, 27.4, 20.6, 11, 2),
    connector = list(visible = F)) %&gt;%
  layout(yaxis = list(categoryarray = c(&quot;Website visit&quot;, &quot;Downloads&quot;, &quot;Potential customers&quot;, &quot;Requested price&quot;, &quot;invoice sent&quot;)))

在Plotly漏斗图中使柱状条之间的区域透明化。

huangapple
  • 本文由 发表于 2023年8月9日 11:36:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864405.html
匿名

发表评论

匿名网友

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

确定