This article describes how to create a table that represents the concept of a brand funnel (similar to a purchase funnel) using R code. For an approach that doesn't use code, see: How to Create a Funnel or Pyramid Chart.
You will need to create the following output tables:
- Consideration (including Top 2 Box NET category)
- Preferred brand/item
Set up your source tables
The easiest way to create the statistics we need for the funnel is to create tables in Displayr. This is done by dragging from the Data Sets section on to your page.
We later reference certain cells within those tables and rearrange them in the final summary table. For the worked example, I created three tables upfront, shown below:
Create an R Output
- From the toolbar, go to Calculation >
- Custom Code.
- Paste the following into the R CODE expression box:
# Set the name of the brands
brands <- c("Coca-Cola","Diet Coke","Coke Zero","Pepsi","Diet Pepsi","Pepsi Max")
# Pull in the tables that will be used to create the brand funnel table
aware <- table.Awareness[brands]
consider <- table.Brand.consider[brands,"NET: Top 2 Box"]
main <- table.Preferred.cola[brands]
# Combine the tables into a single table and rename the rows
table <- cbind("Awareness" = aware, "Consider" = consider, "Preferred" = main)
# Set which output the funnel will use
funnel <- t(table)
# Create ratio calculation
ratio <- funnel["Consider",]/funnel["Preferred",]
# Add calculated output to the table and name the row
funnel <- rbind(funnel, "Ratio" = ratio)
In this example, I am using data that contains cola brands. You will need to update the brands on the first line of code to match your data. Lines 5-7 reference the tables that were created as part of the requirements. To find the table names for the aware, consider, and main inputs, select each table on your page, and from the object inspector, go to Properties > GENERAL > Name.