13.15 漏斗图
<- data.frame(
dat category = c("访问", "下载", "潜客", "报价", "下单"),
value = c(39, 27.4, 20.6, 11, 2)
%>%
) transform(percent = value / cumsum(value))
plot_ly(data = dat) %>%
add_trace(
type = "funnel",
y = ~category,
x = ~value,
color = ~category,
colors = "Set2",
text = ~ paste0(value, "<br>", sprintf("%.2f%%", 100*percent)) ,
hoverinfo = "text",
showlegend = FALSE
%>%
) layout(yaxis = list(
categoryarray = ~category,
title = ""
))
图 13.13: 漏斗图
::plot_ly(data = dat) %>%
plotly::add_trace(
plotlytype = "funnel",
y = ~category,
x = ~value,
marker = list(color = RColorBrewer::brewer.pal(n = 5, name = "Set2")),
textposition = "auto",
textinfo = "value+percent previous",
hoverinfo = "none"
%>%
) ::layout(yaxis = list(categoryarray = ~category, title = "")) plotly
图 13.14: 漏斗图