使Plotly漏斗图中各个条之间的区域透明。

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

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
英文:

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("网站访问", "下载", "潜在客户", "请求价格", "发票已发送"),
    x = c(39, 27.4, 20.6, 11, 2),
    connector = list(fillcolor = "black")) %>%
  layout(yaxis = list(categoryarray = c("网站访问", "下载", "潜在客户", "请求价格", "发票已发送")))

使Plotly漏斗图中各个条之间的区域透明。

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

plot_ly() %>%
  add_trace(
    type = "funnel",
    y = c("网站访问", "下载", "潜在客户", "请求价格", "发票已发送"),
    x = c(39, 27.4, 20.6, 11, 2),
    connector = list(visible = F)) %>%
  layout(yaxis = list(categoryarray = c("网站访问", "下载", "潜在客户", "请求价格", "发票已发送")))

使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-2.html
匿名

发表评论

匿名网友

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

确定