Let me explain with a simple explanation of forming cluster using Sales, Profit, and discount.
Follow the below steps:
1. Create a chart like below
2. Create a calculated field as below
Explanation to the field code -
- Set,seed() is to Set the seed of R's random number generator, which is useful for creating simulations or random objects that can be reproduced. It can be omitted if wanted.
- kmeans() is a function that performs the actual operation of forming clusters. It takes 2 parameters arguments and the number of clusters. arguments are taken from the expression in SCRIPT_REAL() function. The number of clusters can be static or dynamic by using a parameter to provide value.
- data.frame() is used to convert the list of columns into a data frame and pass it as an argument to R functions.
- .arg1,2,3 are arguments that are used in external scripts that fetch the value from tableau variables( fields, parameters, calculated fields) to perform any operations.
3. Drop the created field in the color shelf to observe the clusters.
Let me show you the difference between R and Tableau Clusters using sales-profit and discount
R cluster - using the created field in tableau
Tableau Clusters - using tableau inbuilt Clustering
Hope it helps you!