Title: | Recency, Frequency and Monetary Value Analysis |
---|---|
Description: | Tools for RFM (recency, frequency and monetary value) analysis. Generate RFM score from both transaction and customer level data. Visualize the relationship between recency, frequency and monetary value using heatmap, histograms, bar charts and scatter plots. Includes a 'shiny' app for interactive segmentation. References: i. Blattberg R.C., Kim BD., Neslin S.A (2008) <doi:10.1007/978-0-387-72579-6_12>. |
Authors: | Aravind Hebbali [aut, cre] |
Maintainer: | Aravind Hebbali <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0 |
Built: | 2024-10-23 04:31:21 UTC |
Source: | https://github.com/rsquaredacademy/rfm |
Data for generating bar charts.
rfm_barchart_data(rfm_table)
rfm_barchart_data(rfm_table)
rfm_table |
An object of class |
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # bar chart data rfm_barchart_data(rfm_order) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # bar chart data rfm_barchart_data(rfm_customer)
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # bar chart data rfm_barchart_data(rfm_order) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # bar chart data rfm_barchart_data(rfm_customer)
Generates a segmentation analysis report.
rfm_create_report( rfm_table, segments, interactive = FALSE, title = NULL, author = NULL, folder_name = NULL, file_name = NULL )
rfm_create_report( rfm_table, segments, interactive = FALSE, title = NULL, author = NULL, folder_name = NULL, file_name = NULL )
rfm_table |
An object of class |
segments |
Output from |
interactive |
If |
title |
Title of the report. |
author |
Author of the report. |
folder_name |
The output directory for the report. |
file_name |
The name of the report file. |
## Not run: # analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) rfm_create_report(rfm_result, segments, FALSE, "Customer Segmentation Report") ## End(Not run)
## Not run: # analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) rfm_create_report(rfm_result, segments, FALSE, "Customer Segmentation Report") ## End(Not run)
A dataset containing customer level data.
rfm_data_customer
rfm_data_customer
A tibble with 39,999 rows and 5 variables:
Customer id.
Total amount of all orders.
Date of the most recent transaction.
Total number of transactions/orders.
Number of days since last transaction/order.
#'
First name of the customer.
Last name of the customer.
email id of the customer.
A dataset containing transactions of different customers.
rfm_data_orders
rfm_data_orders
A tibble with 49.6 rows and 3 variables:
Order date.
Customer id
Transaction amount.
First name of the customer.
Last name of the customer.
email id of the customer.
Data for generating heatmap.
rfm_heatmap_data(rfm_table)
rfm_heatmap_data(rfm_table)
rfm_table |
An object of class |
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # heat map data rfm_heatmap_data(rfm_order) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # heat map data rfm_heatmap_data(rfm_customer)
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # heat map data rfm_heatmap_data(rfm_order) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # heat map data rfm_heatmap_data(rfm_customer)
Launches shiny app.
rfm_launch_app()
rfm_launch_app()
## Not run: rfm_launch_app() ## End(Not run)
## Not run: rfm_launch_app() ## End(Not run)
Examine the distribution of monetary scores for the different combinations of frequency and recency scores.
rfm_plot_bar_chart( rfm_table, bar_color = NULL, xaxis_label = NULL, sec_xaxis_label = NULL, yaxis_label = NULL, sec_yaxis_label = NULL, print_plot = TRUE )
rfm_plot_bar_chart( rfm_table, bar_color = NULL, xaxis_label = NULL, sec_xaxis_label = NULL, yaxis_label = NULL, sec_yaxis_label = NULL, print_plot = TRUE )
rfm_table |
An object of class |
bar_color |
Color of the bars. |
xaxis_label |
X axis label. |
sec_xaxis_label |
Secondary x axis label. |
yaxis_label |
Y axis label. |
sec_yaxis_label |
Secondary y axis label. |
print_plot |
logical; if |
Bar chart.
rfm_bar_chart()
has been deprecated and will be made defunct. It has
been provided for compatibility with older versions only, and will be made
defunct at the next release.
Instead use the replacement function rfm_plot_bar_chart()
.
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # bar chart rfm_plot_bar_chart(rfm_order)
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # bar chart rfm_plot_bar_chart(rfm_order)
The heat map shows the average monetary value for different categories of recency and frequency scores. Higher scores of frequency and recency are characterized by higher average monetary value as indicated by the darker areas in the heatmap.
rfm_plot_heatmap( data, brewer_n = 5, brewer_name = "PuBu", xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, legend_title = NULL, interactive = FALSE, print_plot = TRUE )
rfm_plot_heatmap( data, brewer_n = 5, brewer_name = "PuBu", xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, legend_title = NULL, interactive = FALSE, print_plot = TRUE )
data |
An object of class |
brewer_n |
Indicates the number of colors in the palette; RColorBrewer
is used for the color palette of the heatmap; check the documentation of
|
brewer_name |
Palette name; check the documentation of
|
xaxis_label |
X axis label. |
yaxis_label |
Y axis label. |
plot_title |
Title of the plot. |
legend_title |
Legend title. |
interactive |
If |
print_plot |
logical; if |
rfm_heatmap()
has been deprecated and will be made defunct. It has
been provided for compatibility with older versions only, and will be made
defunct at the next release.
Instead use the replacement function rfm_plot_heatmap()
.
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # heat map # ggplot2 rfm_plot_heatmap(rfm_order) # plotly rfm_plot_heatmap(rfm_order, interactive = TRUE) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # heat map rfm_plot_heatmap(rfm_customer)
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # heat map # ggplot2 rfm_plot_heatmap(rfm_order) # plotly rfm_plot_heatmap(rfm_order, interactive = TRUE) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # heat map rfm_plot_heatmap(rfm_customer)
Histograms of recency, frequency and monetary value.
rfm_plot_histogram( rfm_table, metric = "recency", hist_bins = 9, hist_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, interactive = FALSE, print_plot = TRUE )
rfm_plot_histogram( rfm_table, metric = "recency", hist_bins = 9, hist_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, interactive = FALSE, print_plot = TRUE )
rfm_table |
An object of class |
metric |
Metric to be visualized. Defaults to
|
hist_bins |
Number of bins of the histograms. |
hist_color |
Color of the histogram. |
plot_title |
Title of the plot. |
xaxis_label |
X axis label. |
yaxis_label |
Y axis label. |
interactive |
If |
print_plot |
logical; if |
Histograms
rfm_histograms()
has been deprecated and will be made defunct. It has
been provided for compatibility with older versions only, and will be made
defunct at the next release.
Instead use the replacement function rfm_plot_histogram()
.
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # histogram # ggplot2 rfm_plot_histogram(rfm_order, metric = "frequency") # plotly rfm_plot_histogram(rfm_order, metric = "frequency", interactive = TRUE) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # histogram rfm_plot_histogram(rfm_customer)
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # histogram # ggplot2 rfm_plot_histogram(rfm_order, metric = "frequency") # plotly rfm_plot_histogram(rfm_order, metric = "frequency", interactive = TRUE) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # histogram rfm_plot_histogram(rfm_customer)
Segment wise median recency, frequency & monetary value plot.
rfm_plot_median_recency( rfm_segment_table, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE ) rfm_plot_median_frequency( rfm_segment_table, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE ) rfm_plot_median_monetary( rfm_segment_table, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE )
rfm_plot_median_recency( rfm_segment_table, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE ) rfm_plot_median_frequency( rfm_segment_table, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE ) rfm_plot_median_monetary( rfm_segment_table, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE )
rfm_segment_table |
Output from |
sort |
logical; if |
ascending |
logical; if |
flip |
logical; if |
bar_color |
Color of the bars. |
plot_title |
Title of the plot. |
xaxis_label |
X axis label. |
yaxis_label |
Y axis label. |
axis_label_size |
Font size of X axis tick labels. |
axis_label_angle |
Angle of X axis tick labels. |
bar_labels |
If |
interactive |
If |
animate |
If |
print_plot |
logical; if |
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # plots # visualize median recency rfm_plot_median_recency(segments) # plotly rfm_plot_median_recency(segments, interactive = TRUE) # sort in ascending order rfm_plot_median_recency(segments, sort = TRUE, ascending = TRUE) # default sorting is in descending order rfm_plot_median_recency(segments, sort = TRUE) # horizontal bars rfm_plot_median_recency(segments, flip = TRUE) # median frequency rfm_plot_median_frequency(segments) # median monetary value rfm_plot_median_monetary(segments)
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # plots # visualize median recency rfm_plot_median_recency(segments) # plotly rfm_plot_median_recency(segments, interactive = TRUE) # sort in ascending order rfm_plot_median_recency(segments, sort = TRUE, ascending = TRUE) # default sorting is in descending order rfm_plot_median_recency(segments, sort = TRUE) # horizontal bars rfm_plot_median_recency(segments, flip = TRUE) # median frequency rfm_plot_median_frequency(segments) # median monetary value rfm_plot_median_monetary(segments)
Visualize the distribution of customers across orders.
rfm_plot_order_dist( rfm_table, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, bar_label_size = 3, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE )
rfm_plot_order_dist( rfm_table, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, bar_label_size = 3, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE )
rfm_table |
An object of class |
flip |
logical; if |
bar_color |
Color of the bars. |
plot_title |
Title of the plot. |
xaxis_label |
X axis title. |
yaxis_label |
Y axis title. |
bar_label_size |
Size of bar labels. |
bar_labels |
If |
interactive |
If |
animate |
If |
print_plot |
logical; if |
Bar chart.
rfm_order_dist()
has been deprecated and will be made defunct. It has
been provided for compatibility with older versions only, and will be made
defunct at the next release.
Instead use the replacement function rfm_plot_order_dist()
.
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # order distribution rfm_plot_order_dist(rfm_order) # horizontal bars rfm_plot_order_dist(rfm_order, flip = TRUE) # plotly rfm_plot_order_dist(rfm_order, interactive = TRUE) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # order distribution rfm_plot_order_dist(rfm_customer)
# using transaction data analysis_date <- as.Date('2006-12-31') rfm_order <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # order distribution rfm_plot_order_dist(rfm_order) # horizontal bars rfm_plot_order_dist(rfm_order, flip = TRUE) # plotly rfm_plot_order_dist(rfm_order, interactive = TRUE) # using customer data analysis_date <- as.Date('2007-01-01') rfm_customer <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # order distribution rfm_plot_order_dist(rfm_customer)
Customer and revenue distribution by segments.
rfm_plot_revenue_dist( x, flip = FALSE, colors = c("#3b5bdb", "#91a7ff"), legend_labels = c("Revenue", "Customers"), plot_title = "Revenue & Customer Distribution", xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = FALSE, bar_label_size = 2, interactive = FALSE, animate = FALSE, print_plot = TRUE )
rfm_plot_revenue_dist( x, flip = FALSE, colors = c("#3b5bdb", "#91a7ff"), legend_labels = c("Revenue", "Customers"), plot_title = "Revenue & Customer Distribution", xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = FALSE, bar_label_size = 2, interactive = FALSE, animate = FALSE, print_plot = TRUE )
x |
An object of class |
flip |
logical; if |
colors |
Bar colors. |
legend_labels |
Legend labels. |
plot_title |
Title of the plot. |
xaxis_label |
X axis label. |
yaxis_label |
Y axis label. |
axis_label_size |
Font size of X axis tick labels. |
axis_label_angle |
Angle of X axis tick labels. |
bar_labels |
If |
bar_label_size |
Size of bar labels. |
interactive |
If |
animate |
If |
print_plot |
logical; if |
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary segment_overview <- rfm_segment_summary(segments) # revenue distribution # ggplot2 rfm_plot_revenue_dist(segment_overview) # flip rfm_plot_revenue_dist(segment_overview, flip = TRUE) # plotly rfm_plot_revenue_dist(segment_overview, interactive = TRUE)
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary segment_overview <- rfm_segment_summary(segments) # revenue distribution # ggplot2 rfm_plot_revenue_dist(segment_overview) # flip rfm_plot_revenue_dist(segment_overview, flip = TRUE) # plotly rfm_plot_revenue_dist(segment_overview, interactive = TRUE)
Generates tree map to visualize segments.
rfm_plot_segment( table, metric = "customers", interactive = FALSE, print_plot = TRUE )
rfm_plot_segment( table, metric = "customers", interactive = FALSE, print_plot = TRUE )
table |
An object of class |
metric |
Metric to be visualized. Defaults to
|
interactive |
If |
print_plot |
logical; if |
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary segment_overview <- rfm_segment_summary(segments) # treemaps # default metric is customers rfm_plot_segment(segment_overview) # treemap of orders rfm_plot_segment(segment_overview, metric = "orders") # plotly rfm_plot_segment(segment_overview, metric = "revenue", interactive = TRUE)
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary segment_overview <- rfm_segment_summary(segments) # treemaps # default metric is customers rfm_plot_segment(segment_overview) # treemap of orders rfm_plot_segment(segment_overview, metric = "orders") # plotly rfm_plot_segment(segment_overview, metric = "revenue", interactive = TRUE)
Generate scatter plots to examine the relationship between recency, frequency and monetary value.
rfm_plot_segment_scatter( segments, x = "monetary", y = "recency", plot_title = NULL, legend_title = NULL, xaxis_label = NULL, yaxis_label = NULL, interactive = FALSE, animate = FALSE, print_plot = TRUE )
rfm_plot_segment_scatter( segments, x = "monetary", y = "recency", plot_title = NULL, legend_title = NULL, xaxis_label = NULL, yaxis_label = NULL, interactive = FALSE, animate = FALSE, print_plot = TRUE )
segments |
Output from |
x |
Metric to be represented on X axis. |
y |
Metric to be represented on Y axis. |
plot_title |
Title of the plot. |
legend_title |
Title of the plot legend. |
xaxis_label |
X axis label. |
yaxis_label |
Y axis label. |
interactive |
If |
animate |
If |
print_plot |
logical; if |
Scatter plot.
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # visualize # ggplot2 rfm_plot_segment_scatter(segments, "monetary", "recency") # plotly rfm_plot_segment_scatter(segments, "monetary", "recency", interactive = TRUE)
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # visualize # ggplot2 rfm_plot_segment_scatter(segments, "monetary", "recency") # plotly rfm_plot_segment_scatter(segments, "monetary", "recency", interactive = TRUE)
Generates plots for customers, orders, revenue and average order value for each segment.
rfm_plot_segment_summary( x, metric = NULL, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE )
rfm_plot_segment_summary( x, metric = NULL, sort = FALSE, ascending = FALSE, flip = FALSE, bar_color = NULL, plot_title = NULL, xaxis_label = NULL, yaxis_label = NULL, axis_label_size = 8, axis_label_angle = 315, bar_labels = TRUE, interactive = FALSE, animate = FALSE, print_plot = TRUE )
x |
An object of class |
metric |
Metric to be visualized. Defaults to
|
sort |
logical; if |
ascending |
logical; if |
flip |
logical; if |
bar_color |
Color of the bars. |
plot_title |
Title of the plot. |
xaxis_label |
X axis label. |
yaxis_label |
Y axis label. |
axis_label_size |
Font size of X axis tick labels. |
axis_label_angle |
Angle of X axis tick labels. |
bar_labels |
If |
interactive |
If |
animate |
If |
print_plot |
logical; if |
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary segment_overview <- rfm_segment_summary(segments) # plot segment summary # summarize metric for all segments # ggplot2 rfm_plot_segment_summary(segment_overview) # plotly rfm_plot_segment_summary(segment_overview, interactive = TRUE) # select metric to be visualized rfm_plot_segment_summary(segment_overview, metric = "orders") # sort the metric in ascending order rfm_plot_segment_summary(segment_overview, metric = "orders", sort = TRUE, ascending = TRUE) # default sorting is in descending order rfm_plot_segment_summary(segment_overview, metric = "orders", sort = TRUE) # horizontal bars rfm_plot_segment_summary(segment_overview, metric = "orders", flip = TRUE)
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary segment_overview <- rfm_segment_summary(segments) # plot segment summary # summarize metric for all segments # ggplot2 rfm_plot_segment_summary(segment_overview) # plotly rfm_plot_segment_summary(segment_overview, interactive = TRUE) # select metric to be visualized rfm_plot_segment_summary(segment_overview, metric = "orders") # sort the metric in ascending order rfm_plot_segment_summary(segment_overview, metric = "orders", sort = TRUE, ascending = TRUE) # default sorting is in descending order rfm_plot_segment_summary(segment_overview, metric = "orders", sort = TRUE) # horizontal bars rfm_plot_segment_summary(segment_overview, metric = "orders", flip = TRUE)
Examine the relationship between recency, frequency and monetary values.
rfm_rm_plot( segments, xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, print_plot = TRUE ) rfm_fm_plot( segments, xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, print_plot = TRUE ) rfm_rf_plot( segments, xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, print_plot = TRUE )
rfm_rm_plot( segments, xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, print_plot = TRUE ) rfm_fm_plot( segments, xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, print_plot = TRUE ) rfm_rf_plot( segments, xaxis_label = NULL, yaxis_label = NULL, plot_title = NULL, print_plot = TRUE )
segments |
Output from |
xaxis_label |
X axis label. |
yaxis_label |
Y axis label. |
plot_title |
Title of the plot. |
print_plot |
logical; if |
Scatter plot.
rfm_rm_plot()
, rfm_fm_plot()
and rfm_rf_plot()
have
been deprecated and will be made defunct. These functions have been provided
for compatibility with older versions only, and will be made defunct at the
next release.
Instead use the replacement function rfm_plot_segment_scatter()
.
Create segments based on recency, frequency and monetary scores.
rfm_segment( data, segment_names = NULL, recency_lower = NULL, recency_upper = NULL, frequency_lower = NULL, frequency_upper = NULL, monetary_lower = NULL, monetary_upper = NULL )
rfm_segment( data, segment_names = NULL, recency_lower = NULL, recency_upper = NULL, frequency_lower = NULL, frequency_upper = NULL, monetary_lower = NULL, monetary_upper = NULL )
data |
An object of class |
segment_names |
Names of the segments. |
recency_lower |
Lower boundary for recency score. |
recency_upper |
Upper boundary for recency score. |
frequency_lower |
Lower boundary for frequency score. |
frequency_upper |
Upper boundary for frequency score. |
monetary_lower |
Lower boundary for monetary score. |
monetary_upper |
Upper boundary for monetary score. |
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) segments
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) segments
An overview of customer segments.
rfm_segment_summary(segments)
rfm_segment_summary(segments)
segments |
Output from |
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary rfm_segment_summary(segments)
# analysis date analysis_date <- as.Date('2006-12-31') # generate rfm score rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date) # segment names segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers", "Promising", "New Customers", "Can't Lose Them", "At Risk", "Need Attention", "About To Sleep", "Lost") # segment intervals recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1) recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1) frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1) frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5) monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1) monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5) # generate segments segments <- rfm_segment(rfm_result, segment_names, recency_lower, recency_upper, frequency_lower, frequency_upper, monetary_lower, monetary_upper) # segment summary rfm_segment_summary(segments)
Recency, frequency, monetary and RFM score.
rfm_table_customer( data = NULL, customer_id = NULL, n_transactions = NULL, recency = NULL, total_revenue = NULL, analysis_date = NULL, recency_bins = 5, frequency_bins = 5, monetary_bins = 5, ... )
rfm_table_customer( data = NULL, customer_id = NULL, n_transactions = NULL, recency = NULL, total_revenue = NULL, analysis_date = NULL, recency_bins = 5, frequency_bins = 5, monetary_bins = 5, ... )
data |
A |
customer_id |
Unique id of the customer. |
n_transactions |
Number of transactions/orders. |
total_revenue |
Total revenue from the customer. |
analysis_date |
Date of analysis. |
recency_bins |
Number of bins for recency or custom threshold. |
frequency_bins |
Number of bins for frequency or custom threshold. |
monetary_bins |
Number of bins for monetary or custom threshold. |
... |
Other arguments. |
recency |
Days since last visit or date of last visit. |
rfm_table_order
returns a list with the following:
rfm |
RFM table. |
analysis_date |
Date of analysis. |
frequency_bins |
Number of bins used for frequency score. |
recency_bins |
Number of bins used for recency score. |
monetary_bins |
Number of bins used for monetary score. |
threshold |
thresholds used for generating RFM scores. |
analysis_date <- as.Date('2007-01-01') # data includes days since last visit rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # data includes last visit date rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, most_recent_visit, revenue, analysis_date) # access rfm table result <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) result$rfm # using custom threshold rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date, recency_bins = c(115, 181, 297, 482), frequency_bins = c(4, 5, 6, 8), monetary_bins = c(256, 382, 506, 666))
analysis_date <- as.Date('2007-01-01') # data includes days since last visit rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) # data includes last visit date rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, most_recent_visit, revenue, analysis_date) # access rfm table result <- rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date) result$rfm # using custom threshold rfm_table_customer(rfm_data_customer, customer_id, number_of_orders, recency_days, revenue, analysis_date, recency_bins = c(115, 181, 297, 482), frequency_bins = c(4, 5, 6, 8), monetary_bins = c(256, 382, 506, 666))
Recency, frequency, monetary and RFM score.
rfm_table_order( data = NULL, customer_id = NULL, order_date = NULL, revenue = NULL, analysis_date = NULL, recency_bins = 5, frequency_bins = 5, monetary_bins = 5, ... )
rfm_table_order( data = NULL, customer_id = NULL, order_date = NULL, revenue = NULL, analysis_date = NULL, recency_bins = 5, frequency_bins = 5, monetary_bins = 5, ... )
data |
A |
customer_id |
Unique id of the customer. |
order_date |
Date of the transaction. |
revenue |
Revenue from the customer. |
analysis_date |
Date of analysis. |
recency_bins |
Number of bins for recency or custom threshold. |
frequency_bins |
Number of bins for frequency or custom threshold. |
monetary_bins |
Number of bins for monetary or custom threshold. |
... |
Other arguments. |
rfm_table_order
returns a list with the following:
rfm |
RFM table. |
analysis_date |
Date of analysis. |
frequency_bins |
Number of bins used for frequency score. |
recency_bins |
Number of bins used for recency score. |
monetary_bins |
Number of bins used for monetary score. |
threshold |
thresholds used for generating RFM scores. |
analysis_date <- as.Date("2006-12-31") rfm_table_order( rfm_data_orders, customer_id, order_date, revenue, analysis_date ) # access rfm table result <- rfm_table_order( rfm_data_orders, customer_id, order_date, revenue, analysis_date ) result$rfm # using custom threshold rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date, recency_bins = c(115, 181, 297, 482), frequency_bins = c(4, 5, 6, 8), monetary_bins = c(256, 382, 506, 666) )
analysis_date <- as.Date("2006-12-31") rfm_table_order( rfm_data_orders, customer_id, order_date, revenue, analysis_date ) # access rfm table result <- rfm_table_order( rfm_data_orders, customer_id, order_date, revenue, analysis_date ) result$rfm # using custom threshold rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date, recency_bins = c(115, 181, 297, 482), frequency_bins = c(4, 5, 6, 8), monetary_bins = c(256, 382, 506, 666) )