7

I make a plot like this:

plot(
  layer(x=sort(randn(1000),1), y=sort(randn(1000),1), Geom.point),
  layer(x=[-4,4], y=[-4,4], Geom.line(), Theme(default_color=color("black"))))

ScatterPlot

As you can see, the white circle around the points makes the high density parts of the plot almost white.

I would like to change the outer circle color of the points to black (or blue) to better show that the points are really there.

From the Gadfly documentation it seems like the highlight_color argument of Theme() might do that, but it takes a function as argument.

I don't understand how that is supposed to work. Any ideas?

Vincent Zoonekynd
  • 31,893
  • 5
  • 69
  • 78
Skeppet
  • 931
  • 1
  • 9
  • 17

2 Answers2

7

The argument name turns out to be discrete_highlight_color...

It should be a function that modifies the colour used for the plot, typically by making it lighter (a "tint") or darker (a "shade"). In our case, we can just ignore the current colour and return black.

using Color
using Gadfly
plot(
  layer(
    x = sort(randn(1000),1), 
    y = sort(randn(1000),1), 
    Geom.point,
    # Theme(highlight_width=0.0mm) # To remove the border
    Theme( discrete_highlight_color = u -> LCHab(0,0,0) )
  ),
  layer(
    x = [-4,4], 
    y = [-4,4], 
    Geom.line(), 
    Theme(default_color=color("black"))
  )
)

Scatterplot

To find the correct argument, I first typed

code_lowered( Theme, () )

which gives the list of arguments, and then

less( Gadfly.default_discrete_highlight_color )

which shows how the default value is defined.

Vincent Zoonekynd
  • 31,893
  • 5
  • 69
  • 78
  • Plus 1 for including how you got your solution. I think that's very helpful. – Alex A. Apr 01 '15 at 20:05
  • @VincentZoonekynd the last line of code returns this error in Julia 0.6.3: `ERROR: function has multiple methods; please specify a type signature`, despite `using Gadfly` and passing a function. Do you know how to solve it? – miguelmorin Jun 26 '18 at 13:45
  • @VincentZoonekynd `Color` is incompatible with Julia 0.6.3 (`ERROR: Color can't be installed because it has no versions that support 0.6.3 of julia.`). I tried [`Colors`](https://github.com/JuliaGraphics/Colors.jl) and it works. It's just one character change, too small for me to suggest an edit. – miguelmorin Jun 26 '18 at 13:58
0

For those like me trying to solve this problem more recently, I discovered that the best way to get rid of that pesky white ring is through the theme setting highlight_width=0pt

for example

plot(x=rand(10),y=rand(10),Theme(highlight_width=0pt))

I had some additional themes in the below imagean example I did

albiero
  • 81
  • 1
  • 1
  • 7