[英]How to have fixed size in funnel chart but dynamic hover text?
我正在嘗試使用 R 制作漏斗圖。
問題是數字是傾斜的,它們不會有統一的表示。 但是,我們想顯示流程。 那么如何在 R 中制作漏斗圖,其中漏斗的大小是固定的,但文本是動態的並且來自數據框列。
查看源代碼示例: https : //plot.ly/r/funnel-charts/
requiredPackages <- c("plotly")
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
ipak(requiredPackages)
p <- plot_ly(
type = "funnelarea",
values = c(5, 4, 3, 2, 1),
text = c("The 1st","The 2nd", "The 3rd", "The 4th", "The 5th"),
marker = list(colors = c("deepskyblue", "lightsalmon", "tan", "teal", "silver"),
line = list(color = c("wheat", "wheat", "blue", "wheat", "wheat"),
width = c(0, 1, 5, 0, 4))),
textfont = list(family = "Old Standard TT, serif", size = 13, color = "black"),
opacity = 0.65)
p
我想像上面一樣顯示漏斗圖; 但在懸停時我想顯示不同的文本。 隧道只是代表形狀,但懸停將顯示實際值。
根據 OP 的上述評論,我猜他們想要 hoverinfo 從這個值向量c(5,4,3,2,1)
選擇它的文本。
第一個圖/解決方案適用於這個問題:
library(plotly)
plot_ly(
type = "funnelarea",
values = c(5, 4, 3, 2, 1),
text = c("The 1st","The 2nd", "The 3rd", "The 4th", "The 5th"),
marker = list(colors = c("deepskyblue", "lightsalmon", "tan", "teal", "silver"),
line = list(color = c("wheat", "wheat", "blue", "wheat", "wheat"),
width = c(0, 1, 5, 0, 4))),
textfont = list(family = "Old Standard TT, serif", size = 13, color = "black"),
opacity = 0.65,
hovertemplate = '%{value}<extra></extra>')
可以添加更多文本/值。 下面是一個例子。 您可以在此處閱讀更多信息: https : //plot.ly/r/hover-text-and-formatting/
plot_ly(
type = "funnelarea",
values = c(5, 4, 3, 2, 1),
text = c("The 1st","The 2nd", "The 3rd", "The 4th", "The 5th"),
marker = list(colors = c("deepskyblue", "lightsalmon", "tan", "teal", "silver"),
line = list(color = c("wheat", "wheat", "blue", "wheat", "wheat"),
width = c(0, 1, 5, 0, 4))),
textfont = list(family = "Old Standard TT, serif", size = 13, color = "black"),
opacity = 0.65,
hovertemplate = paste('%{value}<extra></extra>' ,
'%{text}<extra></extra>'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.