[英]How to have fixed size in funnel chart but dynamic hover text?
I am trying to have a funnel chart using R.我正在尝试使用 R 制作漏斗图。
The issue is numbers are skewed and they won't have a uniform representation.问题是数字是倾斜的,它们不会有统一的表示。 However, we want to show the flow.
但是,我们想显示流程。 So how can I make a funnel chart in R where the size of the funnel is fixed but the text is dynamic and coming from a dataframe column.
那么如何在 R 中制作漏斗图,其中漏斗的大小是固定的,但文本是动态的并且来自数据框列。
See Source Code Example: https://plot.ly/r/funnel-charts/查看源代码示例: 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
I want to show the funnel chart like above;我想像上面一样显示漏斗图; but on hover I want to show different text.
但在悬停时我想显示不同的文本。 The tunnel is just to represent the shapes but hover will show the actual values.
隧道只是代表形状,但悬停将显示实际值。
Based on the above comment of OP, I am guessing they want to hoverinfo to pick its text from this vector of values c(5,4,3,2,1)
.根据 OP 的上述评论,我猜他们想要 hoverinfo 从这个值向量
c(5,4,3,2,1)
选择它的文本。
The first graph/solution works for that matter:第一个图/解决方案适用于这个问题:
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>')
It's possible to add more text/values.可以添加更多文本/值。 Below is an example of that.
下面是一个例子。 You can read more here: https://plot.ly/r/hover-text-and-formatting/
您可以在此处阅读更多信息: 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.