5
$\begingroup$

This code:

data = {{161.984, 0.00840442}, {97.1036, 0.0305004}, {19.983, 
    0.0609291}, {33.6918, 0.0060476}, {29.209, 0.011549}, {21.4832, 
    0.048097}, {7.32123, 0.124789}, {135.084, 0.0419123}, {32.921, 
    0.0796488}, {141.281, 0.152104}, {16.4971, 0.0288236}, {55.2927, 
    0.0219473}, {52.9662, 0.0511422}, {45.1345, 0.0638596}, {35.6813, 
    0.0524373}, {90.2195, 0.0511422}};

keys = {"agr", "ma1", "ma10", "ma15", "ma6", "ma7", "ma9", "min", 
   "sbus", "scst", "segw", "sfin", "srtl", "stel", "str1", "swhl"};

meanX = Mean[data[[All, 1]]];
meanY = Mean[data[[All, 2]]];

{xmin, xmax} = MinMax[data[[All, 1]]];
{ymin, ymax} = MinMax[data[[All, 2]]];

ListPlot[Table[Callout[data[[i]], keys[[i]]], {i, Length@data}], 
 PlotRange -> All, AspectRatio -> 3/5, 
 PlotRangePadding -> Scaled[0.05], Frame -> True, 
 FrameLabel -> {"Sectoral Value Added", "Sectoral Influence Score"}, 
 PlotTheme -> "Business", 
 PlotLabel -> "Sectoral value added versus influence score", 
 Epilog -> {Red, Thickness[0.005], Dashed, 
   Line[{{meanX, ymin}, {meanX, ymax}}], 
   Line[{{xmin, meanY}, {xmax, meanY}}]}]

generates

enter image description here

I like to replace the circles for {segw, stel, sfin, swhl, str1} with a star shape and color them with Red.

$\endgroup$

5 Answers 5

4
$\begingroup$

With your definitions:

keys1 = {"segw", "stel", "sfin", "swhl", "str1"};

pos = Flatten[Position[keys, #] & /@ keys1, 1];

data1 = data[[Flatten@pos]];

keys2 = Delete[keys, pos];

data2 = Delete[data, pos];

ListPlot[
 {Callout @@@ Transpose[{data1, keys1}],
  Callout @@@ Transpose[{data2, keys2}]},
 PlotMarkers ->
  {Style[★, Red, 12], 
   Style[○, Blue, 10]},
 PlotRange -> All,
 AspectRatio -> 3/5,
 PlotRangePadding -> Scaled[0.05],
 Frame -> True,
 FrameLabel -> {"Sectoral Value Added", "Sectoral Influence Score"},
 PlotTheme -> "Business",
 PlotLabel -> "Sectoral value added versus influence score",
 Prolog -> {Red, Thickness[0.002], Dashed, 
   Line[{{meanX, ymin}, {meanX, ymax}}], 
   Line[{{xmin, meanY}, {xmax, meanY}}]}]

enter image description here

$\endgroup$
5
$\begingroup$
keys = {"agr", "ma1", "ma10", "ma15", "ma6", "ma7", "ma9", "min", 
   "sbus", "scst", "segw", "sfin", "srtl", "stel", "str1", "swhl"};

Markers = {"Circle", "Circle", "Circle", "Circle", "Circle", "Circle",
    "Circle", "Circle", "Circle", "Circle", "OpenStar", "Circle", 
   "OpenStar", "OpenStar", "OpenStar", "OpenStar"};

colors = {Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, 
   Darker[Green], Blue, Darker[Green], Darker[Green], Darker[Green], 
   Darker[Green]};

meanX = Mean[data[[All, 1]]];
meanY = Mean[data[[All, 2]]];

{xmin, xmax} = MinMax[data[[All, 1]]];
{ymin, ymax} = MinMax[data[[All, 2]]];

ListPlot[Table[
  Callout[data[[i]], keys[[i]], CalloutMarker -> Markers[[i]], 
   CalloutStyle -> colors[[i]]], {i, Length[data]}], PlotRange -> All,
  AspectRatio -> 3/5, PlotRangePadding -> Scaled[0.05], Frame -> True,
  PlotStyle -> PointSize[0.001], 
 FrameLabel -> {"Sectoral Value Added", "Sectoral Influence Score"}, 
 PlotTheme -> "Business", 
 PlotLabel -> "Sectoral value added versus influence score", 
 Epilog -> {Red, Thickness[0.005], Dashed, 
   Line[{{meanX, ymin}, {meanX, ymax}}], 
   Line[{{xmin, meanY}, {xmax, meanY}}]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks for editing :) $\endgroup$
    – eldo
    Mar 1 at 15:40
3
$\begingroup$

This is a bit hack, to cover circle underneath, I increased the star size. Probably you can post process the figure you have to get you want.

Show[ListPlot[Table[Callout[data[[i]], keys[[i]]], {i, Length@data}], 
  PlotRange -> All, AspectRatio -> 3/5, 
  PlotRangePadding -> Scaled[0.05], Frame -> True, 
  FrameLabel -> {"Sectoral Value Added", "Sectoral Influence Score"}, 
  PlotTheme -> "Business", 
  PlotLabel -> "Sectoral value added versus influence score", 
  Epilog -> {Red, Thickness[0.005], Dashed, 
    Line[{{meanX, ymin}, {meanX, ymax}}], 
    Line[{{xmin, meanY}, {xmax, meanY}}]}], 
 ListPlot[
  Join @@ Extract[data, 
    Position[keys, #] & /@ 
     ToString /@ {segw, stel, sfin, swhl, str1}], PlotStyle -> Red, 
  PlotMarkers -> {"\[FivePointedStar]", 25}]]

enter image description here

$\endgroup$
3
$\begingroup$

An Association - based solution (with callouts placed automatically)

asc = AssociationThread[keys -> data];

ka = {"segw", "stel", "sfin", "swhl", "str1"};

pa = KeyTake[ka] @ asc;

pb = KeyTake[Complement[keys, ka]] @ asc;

Show[
 ListPlot[pb, PlotMarkers -> Style[\[EmptyCircle], Blue, 10], PlotTheme -> "Business"],
 ListPlot[pa, PlotMarkers -> Style[\[FivePointedStar], Red, 12]],
 AspectRatio -> 3/5,
 Epilog ->
  {Red, Thickness[0.003], Dashed,
   Line[{{meanX, ymin}, {meanX, ymax}}],
   Line[{{xmin, meanY}, {xmax, meanY}}]},
 Frame -> True,
 FrameLabel -> {"Sectoral Value Added", "Sectoral Influence Score"},
 ImageSize -> 500,
 PlotLabel -> "Sectoral value added versus influence score",
 PlotRange -> All,
 PlotRangePadding -> Scaled[0.05]]

enter image description here

$\endgroup$
2
$\begingroup$

You could split your data into two sets, and plot them with different settings for PlotStyle and PlotMarkers:

ListPlot[
 GatherBy[Table[Callout[data[[i]], keys[[i]]], {i, Length@data}], 
  MatchQ[Callout[_, "segw" | "stel" | "sfin" | "swhl" | "str1"]]], 
 PlotRange -> All, AspectRatio -> 3/5, 
 PlotRangePadding -> Scaled[0.05], Frame -> True,
 PlotStyle -> {Blue, Red}, 
 PlotMarkers -> {"\[EmptyCircle]", "\[FivePointedStar]"}, 
 FrameLabel -> {"Sectoral Value Added", "Sectoral Influence Score"}, 
 PlotTheme -> "Business", 
 PlotLabel -> "Sectoral value added versus influence score", 
 Epilog -> {Red, Thickness[0.005], Dashed, 
   Line[{{meanX, ymin}, {meanX, ymax}}], 
   Line[{{xmin, meanY}, {xmax, meanY}}]}]
$\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.