### Question

How to divide a scatter plot with any linear line.

For example, in the below scatter plot, how to manually input 2 dots and divide the it into 2 parts with color in the mark or in the background.

KNOWLEDGE BASE

How to divide a scatter plot with any linear line.

For example, in the below scatter plot, how to manually input 2 dots and divide the it into 2 parts with color in the mark or in the background.

- Tableau Desktop
- Tableau Server
- Tableau Cloud

The steps are as follows

1. Create 4 parameters as [X1], [Y1], [X2], [Y2] to input 2 dots for the linear line.

2. Create a Slope calculation using the 4 Parameters.

AVG([Y2]-[Y1])/AVG([X2]-[X1])3. Create a Linear line function to divide the marks into two parts -- "IN" and "OUT".

IF SUM([Quantity])>=[! Slope]*SUM([Sales])+([Y2]-[! Slope]*[X2]) THEN "IN" ELSEIF SUM([Quantity])<[! Slope]*SUM([Sales])+([Y2]-[! Slope]*[X2]) THEN "OUT" END4. Add the calculation in Step 3 to [Color] Mark.

The worksheet [Option 1] and process video [divide option 1.mp4] are attached.

Please check the below images.

The steps are as follows

1. Create 4 parameters as [X1], [Y1], [X2], [Y2] to input 2 dots for the linear line.

2. Create a Slope calculation using the 4 Parameters.

AVG([Y2]-[Y1])/AVG([X2]-[X1])3. Create a calculation to calculate the Y of the Linear line graph.

IF INDEX()%2 = 0 THEN AVG([Y1]) ELSEIF INDEX()%2 = 1 THEN AVG([Y2]) END4. Create a Linear line function.

SUM([Sales])*[! Slope]+WINDOW_MIN([! Y])5. Add the calculation in Step 4 to [Rows] Shelf and set it as a dual-axis.

6. Set the Mark Type of the calculation in Step 4 as [Area] and delete the Measure Names in this shelf.

The worksheet [Option 2] and process video [divide option 2.mp4] are attached.

Please check the below images.

Understanding and Using Scatter Plots | Tableau

Manually Calculating Trend Lines

Thank you for providing your feedback on the effectiveness of the article.

Open new Case

Continue Searching

Knowledge Base

Community

Product Help

Training and Tutorials