I am trying to have a funnel chart using 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.
See Source Code Example: 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 the hoverinfo to pick its text from this vector of values 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/
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>'))