https://github.com/pedropark99/ggfunnel
A R package to build Power BI like funnel charts in R, using {ggplot2}
https://github.com/pedropark99/ggfunnel
funnel-chart ggplot2 powerbi r
Last synced: 3 months ago
JSON representation
A R package to build Power BI like funnel charts in R, using {ggplot2}
- Host: GitHub
- URL: https://github.com/pedropark99/ggfunnel
- Owner: pedropark99
- License: other
- Created: 2022-12-23T21:27:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-12T00:10:37.000Z (over 2 years ago)
- Last Synced: 2025-01-26T19:12:15.270Z (5 months ago)
- Topics: funnel-chart, ggplot2, powerbi, r
- Language: R
- Homepage: https://pedropark99.github.io/ggfunnel/
- Size: 614 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `ggfunnel`
## Overview
`{ggfunnel}` is a R package that uses `{ggplot2}` to create Power BI
like funnel charts in R. We give below a very basic example, but, if you want to know
more details about the package, and how it works, I recommend you to see `vignette("funnel")`.## How to get it ?
For now, `{ggfunnel}` is available only at GitHub. You can download and install the package with the `devtools::install_github()` function:
```r
devtools::install_github("pedropark99/ggfunnel")
```## A basic example of use
The main functionality of the package is available trough the `ggfunnel::funnel()` function. It is responsible for producing the plot, and you usually define 3 arguments in this function, which are:
- `data`: the data.frame with the data you want to use in the plot;
- `values`: the column name where are the values you want to display in your funnel chart. In other words, the numerical data that you want to visualize in the chart;
- `levels`: the column name with the "levels" (or the "groups") you want to display in your funnel chart. In other words, the categorical data that identifies each level in the funnel;In the example below, we are using the `ggfunnel::aggregates` data.frame to build a basic funnel chart:
```r
ggfunnel::aggregates
```
```
# A tibble: 5 × 2
Step N_users
1 A 4389
2 B 3100
3 C 2005
4 D 500
5 E 120
```The `N_users` column is the column with numerical data, so I give it to the `values` argument of the function. This way, these values will be used to determine the widths of each rectangle in the funnel chart.
In contrast, the `Step` column contains the categorical data of the dataset. That is why I gave this column to the `levels` argument of the function. As a result, the values of this column will be used to determine the "levels" of the funnel chart.
```r
library(ggfunnel)
plot <- ggfunnel::funnel(
data = ggfunnel::aggregates,
values = N_users, levels = Step
)print(plot)
```
## A simple (but far from perfect) approach
`{ggfunnel}` is kind of a experimental package, and it is far from perfect. As a result, it does not contain all things you might want/need for building a funnel chart.
This means that, currently, `{ggfunnel}` gives you the minimal code necessary to produce a decent funnel chart. But it does give much more functionality than that. It also makes some assumptions about your data that might not hold, and it does not contain some features that you might find at Power BI (e.g. percentage labels).
But, even being a very simple package, `ggfunnel::funnel()` always returns the raw `ggplot` object that describes the funnel chart. This means that the package gives you a lot of freedom to customize (or to complement) the output in the way you might need (see `vignette("funnel")` for more details on how to customize/complement the `ggfunnel::funnel()` output).
However, the package needs some work to be a more robust and complete piece of code, for sure. If you think you can make `{ggfunnel}` better I would be happy to review a PR from you!