6
$\begingroup$

I am trying to create an easy legend with bubbles for a Bubblechart.

The legend should have the BubbleSizes -> {.02, .05}, for the scores 3 to 8 and ranging with the rainbow colors. Basically this but with bubbles of increasing size, instead of squares: enter image description here

Is there any easy way to do this???

This is my code right now:

legend2 = 
 BarLegend[{"Rainbow", {3, 8}}, 5, 
  LegendLabel -> Style["Happiness Score", 16], LegendLayout -> "Row"]
$\endgroup$

1 Answer 1

7
$\begingroup$
dt = Range[3, 8];

SwatchLegend[ColorData["Rainbow"] /@ Rescale[dt], 
  dt, 
  LegendLabel -> Style["Happiness Score", 16], 
  LegendLayout -> {"Row", 1}, LegendMarkers -> "Bubble", 
  LegendMarkerSize -> 5 dt] 

enter image description here

Change the second argument from dt to Rescale[dt, MinMax@dt, {.02, .05}] to change the labels:

enter image description here

$\endgroup$
5
  • 3
    $\begingroup$ Can also use PointLegend and omit LegendMarkers. $\endgroup$ Jan 8, 2020 at 17:54
  • $\begingroup$ Is there a way to make the numbers smaller? LegendMarkerSize only changes the size of the bubbles $\endgroup$
    – Faye Drew
    Jan 8, 2020 at 19:27
  • $\begingroup$ @Faye, pls see the new version. $\endgroup$
    – kglr
    Jan 8, 2020 at 19:41
  • $\begingroup$ Now, how did you figure out there is such "Bubble" markers? @kglr ? :) $\endgroup$ Feb 6, 2020 at 22:25
  • 1
    $\begingroup$ @MinHsuanPeng, it is in the docs: SwatchLegend >> Options >> LegendMarkers $\endgroup$
    – kglr
    Feb 6, 2020 at 22:43

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.