[英]Center the bars in Funnel chart
I'm trying to make funnel chart in R. As an example I took code from this page https://analyzecore.com/2015/06/23/sales-funnel-visualization-with-r/ But the strange thing is, which I could not get, why my bars are skewed to the left side? 我正在尝试在R中制作漏斗图。例如,我从此页面中获取了代码https://analyzecore.com/2015/06/23/sales-funnel-visualization-with-r/但是,奇怪的是,为什么我的杠铃偏向左侧?
Funnel data:
Category Number
1 total_members 1000
2 paid_members 936
3 cancellations 452
4 refunds 34
library(ggplot2)
ggplot() +
theme_minimal() +
coord_flip() +
scale_fill_manual(values=cols)+
geom_bar(data=funnel_data, aes(x=Category, y=Number, fill=Category), stat="identity", width=1)
Results in 结果是
If you just run the piece of code from the article, this one for example: 如果您仅运行本文中的代码段,则该代码段例如:
ggplot() +
theme_minimal() +
coord_flip() +
scale_fill_manual(values=cols) +
geom_bar(data=df.all, aes(x=step, y=number, fill=content), stat="identity", width=1)
It will give you a nice example with bars centered by X: 这将为您提供一个很好的示例,其中的条形以X为中心:
I have no clue what is the issue in this case. 我不知道这种情况是什么问题。 Would be very glad for any assisance.
希望得到您的协助。
This is different approach, but works - create second geom_bar
geom with negative values: 这是一种不同的方法,但是
geom_bar
-创建带有负值的第二个geom_bar
geom:
library(ggplot2)
# Using OPs data
ggplot(funnel_data, aes(Category, fill = Category)) +
geom_bar(aes(y = Number), stat = "identity", width = 1) +
geom_bar(aes(y = -Number), stat = "identity", width = 1) +
theme_minimal() +
coord_flip()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.