英文:
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)?
The code for the plot is below (this is the example on the plotly website):
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
答案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("网站访问", "下载", "潜在客户", "请求价格", "发票已发送")))
如果透明意味着隐藏区域,可以使用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("网站访问", "下载", "潜在客户", "请求价格", "发票已发送")))
英文:
It can be set via add_trace(connector = list(fillcolor))
, see reference here.
For example setting it to "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")))
<hr>
If transparent meant hiding the area, use 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")))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论