Search code examples
scatter-plotlibreofficelibreoffice-calc

Libreoffice scatterplot with different classes


I have some 2D points that I want to plot, but each point belongs to a class. When doing the scatterplot I want each class to be plotted with a different color or symbol, so I can distinguish them (ideally I also want to control which color and symbol I assign to each class)

This is my data

enter image description here

This is what I have with scatterplot:

enter image description here

And this is what I want to have (without having to manually create new data Series)

enter image description here


Solution

  • For colors, use a Bubble chart and set the Fill Color data range. Apparently, Scatter cannot do this.

    To illustrate, start with the following data. The reason for the final row with the large bubble size is to make all of the other bubbles relatively small, as explained at https://peltiertech.com/Excel/Charts/ControlBubbleSizes.html.

    X       Y       Class   Color       Bubble Size
    0.10    0.10    1       255         1
    0.11    0.10    1       255         1
    0.10    0.12    1       255         1
    0.11    0.11    1       255         1
    0.20    0.20    2       16711680    1
    0.21    0.20    2       16711680    1
    0.20    0.22    2       16711680    1
    0.21    0.21    2       16711680    1
    0.15    0.15    3       16776960    1
    0.16    0.15    3       16776960    1
    0.16    0.15    3       16776960    1
    0.15    0.16    3       16776960    1
    0.20    0.05    0       0           100
    

    Select A1 through B14 and go to Insert -> Chart -> Bubble. Press Next, Next. Set these ranges.

    Fill Color    $Sheet1.$D$1:$D$14
    Bubble Sizes  $Sheet1.$E$1:$E$14
    X-Values      $Sheet1.$A$1:$A$14
    Y-Values      $Sheet1.$B$1:$B$14
    

    data ranges

    Press Next, check Display Grids: X axis, and uncheck Display legend. Finally, press Finish.

    Now the big, black bubble needs to be hidden. To do this, double-click on the chart and then right-click on the bubble. Holding down Shift may make it easier to select a single bubble.

    format data point

    Choose Format Data Point, press None, and then OK.

    One final improvement is to set up a table for the color of each class. Add the following data in G1 through H4.

    Class   Color
    1       =COLOR(0,0,255)
    2       =COLOR(255,0,0)
    3       =COLOR(255,255,0)
    

    Then set the formula for D2 to =VLOOKUP(C2,G$2:H$4,2) and fill down to D13. (D14 can just be left at 0, which is black).

    It seems that Bubble charts do not allow different symbols for icons. So if using different symbols is required, it may be necessary to use a scatter chart and format each data point manually, or use a series for each class.

    For large amounts of data, a macro could probably do this. Post a question on this forum if you want to attempt this and get stuck, as I have some experience with macros that format charts.