# How to create 2d ListPlot with distinct colors?

I have a data set of type (x,y,E), where E can assume 4 distinct configurations (0,0), (1,0), (0,1) or (1,1). I want to create a 2D plot using ListPlot considering the rules:

1. If E=(0,0), then print red
2. If E=(1,0), then print blue
3. If E=(0,1), then print green
4. If E=(1,1), then print black the respective coordinate (x,y). See illustrative Figure below data=Uncompress[FromCharacterCode[
Flatten[ImageData[Import["https://i.stack.imgur.com/hQ9L8.png"], "Byte"]]]]


The code doesn't work

ListPlot[Partition[data[[All ;; 2]], 2, 1],
PlotStyle -> (Rest[
data[[All, -1]]] /. {{0, 1} -> Green, {1, 0} -> Blue, {0, 0} ->
Red, {1, 1} -> Black})]


Can anybody help me?

colorRule = Association[{{0, 0} -> Red, {1, 0} -> Blue, {0, 1} ->
Green, {1, 1} -> Black}];


Wrap each xy pair with List and map colorRule on the last column to get a list of colors to be used as PlotStyle option setting:

colors = (colorRule /@ data[[All, -1]]);

ListPlot[List /@ data[[All, ;; 2]],
PlotStyle -> colors,
BaseStyle -> PointSize[Large]] Alternatively, use Style to assign the desired colors to the xy pairs::

styledData = Style[{#, #2}, colorRule @ #3] & @@@ data;

ListPlot[styledData, BaseStyle -> PointSize[Large]] • A much faster version might be Graphics[Point[data[[All, ;; 2]], VertexColors -> colors], BaseStyle -> PointSize[Large]] Jun 30, 2020 at 7:05

In addition to providing colors for each point individually as in kglr's answer, you can also group the elements by the last element before plotting. This can be done in several different ways. Here's one example:

groups = GroupBy[data, Last][[All, All, ;; 2]];
ListPlot[{
groups[{0, 1}],
groups[{1, 0}],
groups[{0, 0}],
groups[{1, 1}]
},
PlotStyle -> {Green, Blue, Red, Black},
BaseStyle -> PointSize[Large]
] 