1
$\begingroup$

Consider the following Dataset:

ClearAll[tbl];
tbl = Dataset[{
    <|"a" -> "P", "x" -> 0.1, "y" -> 1.2|>,
    <|"a" -> "Q", "x" -> 0.1, "y" -> 1.75|>,
    <|"a" -> "R", "x" -> 0.2, "y" -> 0.67|>,
    <|"a" -> "P", "x" -> 0.3, "y" -> 2.22|>
}];

I can ListPlot columns x and y:

tbl // (Query[All, {"x", "y"}] /* ListPlot)

But I want the points to have three different colours based upon their values in the a column. It seems that PlotMarkers applies to the entire data set, not to individual points.

What is the best way to achieve this?

$\endgroup$
3
  • 2
    $\begingroup$ tbl // Query[GroupBy["a"], All, {"x", "y"}] // ListPlot? $\endgroup$
    – kglr
    Mar 10, 2022 at 1:33
  • 2
    $\begingroup$ As @kglr suggested but use ListPlot[#, PlotMarkers -> Automatic] & if you want different shapes as well as different colors. $\endgroup$
    – Bob Hanlon
    Mar 10, 2022 at 1:39
  • $\begingroup$ @kglr Thank you! $\endgroup$ Mar 10, 2022 at 1:42

1 Answer 1

2
$\begingroup$
tbl // Query[GroupBy["a"], All, {"x", "y"}] // ListPlot

enter image description here

Use ListPlot[#, PlotMarkers -> Automatic] & as suggested by Bob Hanlon in comments to get:

enter image description here

Alternatively, use ListPlot[#, PlotTheme -> "OpenMarkers"] & to get

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.