# Change ListPlot marker style depending on coordinates

I have a set of data in an array; each element of the overall array is a list of the form $\{x, y, c\}$, where $c$ is a number representing a property of the data point $\{x, y\}$. I can plot these data pretty straightforwardly on a ListPlot:

RandomSeed[719];
data = RandomReal[{0, 1}, {100, 3}];
wrappeddata1 = Style[{#[[1]], #[[2]]}, ColorData["DarkRainbow"][#[[3]]]] & /@ data;
ListPlot[wrappeddata1, AspectRatio -> 1, ImageSize -> Large]


However, I need to differentiate between the data in a particular region of the plot (given by an inequality $f(x,y) < c$) and the data outside of this region. I can change the color of the data points easily enough; for example, I can color all points with $x^2 + y^2 < 1/4$ black:

wrappeddata2 = Style[{#[[1]], #[[2]]}, If[#[[1]]^2 + #[[2]]^2 < 1/4, Black,
ColorData["DarkRainbow"][#[[3]]]]] & /@ data;
ListPlot[wrappeddata2, AspectRatio -> 1, ImageSize -> Large]


What I would really like to do, though, is change the markers' shape according to their location, instead of changing their color. In other words, I'd like to turn every red dot into a red triangle (say) inside a given region, and leave all the other markers as is. If I split the data into two lists, though, I can't change the marker without losing the coloring; the command

ListPlot[GatherBy[wrappeddata1, #[[1, 1]]^2 + #[[1, 2]]^2 > 1/4 &],
AspectRatio -> 1, ImageSize -> Large]


yields something that's identical to the first plot, while

ListPlot[GatherBy[wrappeddata1, #[[1, 1]]^2 + #[[1, 2]]^2 > 1/4 &],
AspectRatio -> 1, ImageSize -> Large, PlotMarkers -> {"●", "×"}]


loses the coloring information:

(GatherBy also has the problem that it doesn't reliably sort the values according whether they're inside or outside the desired region, but that's a side issue and easily solved if necessary. I'm really more concerned with retaining the coloring while using different marker styles.)

You could use BubbleChart

BubbleChart[
GroupBy[data, #[[1]]^2 + #[[2]]^2 > 1/4 &] /. {a_, b_, c_} :> {a, b, 1},
ChartLegends -> Automatic,
ChartStyle -> {Blue, Red},
ChartElements -> {Graphics[Disk[]], Graphics[Rectangle[]]}]


To preserve the original color scheme:

BubbleChart[
GroupBy[data, #[[1]]^2 + #[[2]]^2 > 1/4 &],
BubbleSizes -> {0.07, 0.07},
ColorFunction -> (ColorData["DarkRainbow"][#3] &),
ChartElements -> {Graphics[Disk[]], Graphics[{Rectangle[]}]}]


• I haven't really looked into BubblePlot. I did want to retain the original color-coding both inside & outside the region, though. (Sorry if that wasn't clear from my question — I've edited it to be clearer.) Is it possible to do this with BubblePlot? Jul 21, 2017 at 2:03
• See updated answer
– eldo
Jul 21, 2017 at 8:37

Here is one way to do it.

SeedRandom[42]
data = RandomReal[{0, 1}, {100, 3}];

With[{c = 1/4},
wrappedData =
Style[
{#[[1]], #[[2]]},
If[(#[[1]]^2 + #[[2]]^2) < c, Black, Red]] & /@ data]];
Show[
ListPlot[wrappedData, AspectRatio -> 1, ImageSize -> Large],
Graphics[Circle[{0, 0}, 1/2]]]


I have use only red and black coloring to make the results clearer. But with

With[{c = 1/4},
wrappedData =
Style[
{#[[1]], #[[2]]},
If[(#[[1]]^2 + #[[2]]^2) < c,
Black, ColorData["DarkRainbow"][#[[3]]]]] &
/@ data];


you can have your rainbow coloring outside the circle of radius 1/2.

To get different markers, abandoning ListPlot might be a good idea. Consider

With[{c = 1/4},
markers =
If[(#[[1]]^2 + #[[2]]^2) < c,
Text[
Style["■", 20, ColorData["DarkRainbow"][#[[3]]]],
{#[[1]], #[[2]]}],
Text[
Style["●", 13, ColorData["DarkRainbow"][#[[3]]]],
{#[[1]], #[[2]]}]] &
/@ data];

Graphics[{markers, Circle[{0, 0}, 1/2, {0, 90 °}]},
ImageSize -> Large, Frame -> True]