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?
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:
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:
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.