英文:
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("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"))))
如果透明意味着隐藏该区域,请使用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"))))
英文:
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")))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论